forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
add new v32 properties for Path Items #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
93d8a47
add new v32 properties for Path Items
kilifu 9f0d2c1
Merge branch 'feat/oai-3-2-support' into feat/5-new-fields-path-item
baywet 1cac1a2
move query and AdditionalOperations to OpenApiOperation
kilifu e3ae554
Merge branch 'feat/5-new-fields-path-item' of https://github.com/Bink…
kilifu 40a22f8
Merge branch 'feat/oai-3-2-support' into feat/5-new-fields-path-item
kilifu a256053
chore: reverts some undesired changes
baywet f7dc7ee
feat: adds support for additional operations in OAI 3.2
baywet d608cdc
chore: linting
baywet 1a104d9
chore: fixes test files for path item additional operations
baywet c6b1b0e
chore: updates public export
baywet 4801b06
chore: make new unit tests build
baywet 0520443
chore: refactoring
baywet 4f47916
tests: fixes additional operation test file
baywet 71e51ea
tests: fixes test definitions
baywet cbc2934
fix: do not serialized extraneous operations in v2
baywet 39f300d
tests: fixes unit tests for path item serialization
baywet 30227ef
Merge branch 'feat/oai-3-2-support' into feat/5-new-fields-path-item
baywet fefec09
test: adds tests for 30 deserialization of path items with extra ops
baywet 0781a89
chore: moves tests definitions to the right location
baywet 49f9560
tests: adds deserialization tests for 3.1 path item extra operations
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
246 changes: 246 additions & 0 deletions
246
test/Microsoft.OpenApi.Readers.Tests/V32Tests/OpenApiPathItemTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.OpenApi.Reader; | ||
using Microsoft.OpenApi.Tests; | ||
using Xunit; | ||
|
||
namespace Microsoft.OpenApi.Readers.Tests.V32Tests | ||
{ | ||
public class OpenApiPathItemTests | ||
{ | ||
private const string SampleFolderPath = "V32Tests/Samples/OpenApiPathItem/"; | ||
|
||
[Fact] | ||
public async Task ParsePathItemWithQueryAndAdditionalOperationsV32Works() | ||
{ | ||
// Arrange & Act | ||
var result = await OpenApiDocument.LoadAsync($"{SampleFolderPath}pathItemWithQueryAndAdditionalOperations.yaml", SettingsFixture.ReaderSettings); | ||
var pathItem = result.Document.Paths["/pets"]; | ||
|
||
// Assert | ||
Assert.Equal("Pet operations", pathItem.Summary); | ||
Assert.Equal("Operations available for pets", pathItem.Description); | ||
|
||
// Regular operations | ||
Assert.True(pathItem.Operations?.ContainsKey(HttpMethod.Get)); | ||
var getOp = pathItem.Operations[HttpMethod.Get]; | ||
Assert.Equal("getPets", getOp.OperationId); | ||
|
||
Assert.True(pathItem.Operations?.ContainsKey(HttpMethod.Post)); | ||
var postOp = pathItem.Operations[HttpMethod.Post]; | ||
Assert.Equal("createPet", postOp.OperationId); | ||
|
||
// Query operation should now be on one of the operations | ||
// Since the YAML structure changed, we need to check which operation has the query | ||
Assert.NotNull(getOp.Query); | ||
Assert.Equal("Query pets with complex filters", getOp.Query.Summary); | ||
Assert.Equal("queryPets", getOp.Query.OperationId); | ||
Assert.Single(getOp.Query.Parameters); | ||
Assert.Equal("filter", getOp.Query.Parameters[0].Name); | ||
|
||
// Additional operations should now be on one of the operations | ||
Assert.NotNull(getOp.AdditionalOperations); | ||
Assert.Equal(2, getOp.AdditionalOperations.Count); | ||
|
||
Assert.True(getOp.AdditionalOperations.ContainsKey("notify")); | ||
var notifyOp = getOp.AdditionalOperations["notify"]; | ||
Assert.Equal("Notify about pet updates", notifyOp.Summary); | ||
Assert.Equal("notifyPetUpdates", notifyOp.OperationId); | ||
Assert.NotNull(notifyOp.RequestBody); | ||
|
||
Assert.True(getOp.AdditionalOperations.ContainsKey("subscribe")); | ||
var subscribeOp = getOp.AdditionalOperations["subscribe"]; | ||
Assert.Equal("Subscribe to pet events", subscribeOp.Summary); | ||
Assert.Equal("subscribePetEvents", subscribeOp.OperationId); | ||
Assert.Single(subscribeOp.Parameters); | ||
Assert.Equal("events", subscribeOp.Parameters[0].Name); | ||
} | ||
|
||
[Fact] | ||
public async Task ParsePathItemWithV32ExtensionsWorks() | ||
{ | ||
// Arrange & Act | ||
var result = await OpenApiDocument.LoadAsync($"{SampleFolderPath}pathItemWithV32Extensions.yaml", SettingsFixture.ReaderSettings); | ||
var pathItem = result.Document.Paths["/pets"]; | ||
|
||
// Assert | ||
Assert.Equal("Pet operations", pathItem.Summary); | ||
Assert.Equal("Operations available for pets", pathItem.Description); | ||
|
||
// Regular operations | ||
Assert.True(pathItem.Operations?.ContainsKey(HttpMethod.Get)); | ||
var getOp = pathItem.Operations[HttpMethod.Get]; | ||
Assert.Equal("getPets", getOp.OperationId); | ||
|
||
// Query operation from extension should now be on the operation | ||
Assert.NotNull(getOp.Query); | ||
Assert.Equal("Query pets with complex filters", getOp.Query.Summary); | ||
Assert.Equal("queryPets", getOp.Query.OperationId); | ||
|
||
// Additional operations from extension should now be on the operation | ||
Assert.NotNull(getOp.AdditionalOperations); | ||
Assert.Single(getOp.AdditionalOperations); | ||
Assert.True(getOp.AdditionalOperations.ContainsKey("notify")); | ||
var notifyOp = getOp.AdditionalOperations["notify"]; | ||
Assert.Equal("Notify about pet updates", notifyOp.Summary); | ||
Assert.Equal("notifyPetUpdates", notifyOp.OperationId); | ||
} | ||
|
||
[Fact] | ||
public async Task SerializeV32PathItemToV31ProducesExtensions() | ||
{ | ||
// Arrange | ||
var pathItem = new OpenApiPathItem | ||
{ | ||
Summary = "Test path", | ||
Operations = new Dictionary<HttpMethod, OpenApiOperation> | ||
{ | ||
[HttpMethod.Get] = new OpenApiOperation | ||
{ | ||
Summary = "Get operation", | ||
OperationId = "getOp", | ||
Query = new OpenApiOperation | ||
{ | ||
Summary = "Query operation", | ||
OperationId = "queryOp", | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
}, | ||
AdditionalOperations = new Dictionary<string, OpenApiOperation> | ||
{ | ||
["notify"] = new OpenApiOperation | ||
{ | ||
Summary = "Notify operation", | ||
OperationId = "notifyOp", | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
} | ||
}, | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Act | ||
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1); | ||
|
||
// Assert | ||
Assert.Contains("x-oas-query:", yaml); | ||
Assert.Contains("x-oas-additionalOperations:", yaml); | ||
Assert.Contains("queryOp", yaml); | ||
Assert.Contains("notifyOp", yaml); | ||
} | ||
|
||
[Fact] | ||
public async Task SerializeV32PathItemToV3ProducesExtensions() | ||
{ | ||
// Arrange | ||
var pathItem = new OpenApiPathItem | ||
{ | ||
Summary = "Test path", | ||
Operations = new Dictionary<HttpMethod, OpenApiOperation> | ||
{ | ||
[HttpMethod.Get] = new OpenApiOperation | ||
{ | ||
Summary = "Get operation", | ||
OperationId = "getOp", | ||
Query = new OpenApiOperation | ||
{ | ||
Summary = "Query operation", | ||
OperationId = "queryOp", | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
}, | ||
AdditionalOperations = new Dictionary<string, OpenApiOperation> | ||
{ | ||
["notify"] = new OpenApiOperation | ||
{ | ||
Summary = "Notify operation", | ||
OperationId = "notifyOp", | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
} | ||
}, | ||
Responses = new OpenApiResponses | ||
{ | ||
["200"] = new OpenApiResponse { Description = "Success" } | ||
} | ||
} | ||
} | ||
}; | ||
|
||
// Act | ||
var yaml = await pathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0); | ||
|
||
// Assert | ||
Assert.Contains("x-oas-query:", yaml); | ||
Assert.Contains("x-oas-additionalOperations:", yaml); | ||
Assert.Contains("queryOp", yaml); | ||
Assert.Contains("notifyOp", yaml); | ||
} | ||
|
||
[Fact] | ||
public void PathItemShallowCopyIncludesV32Fields() | ||
{ | ||
// Arrange | ||
var original = new OpenApiPathItem | ||
{ | ||
Summary = "Original", | ||
Operations = new Dictionary<HttpMethod, OpenApiOperation> | ||
{ | ||
[HttpMethod.Get] = new OpenApiOperation | ||
{ | ||
Summary = "Get operation", | ||
OperationId = "getOp", | ||
Query = new OpenApiOperation | ||
{ | ||
Summary = "Query operation", | ||
OperationId = "queryOp" | ||
}, | ||
AdditionalOperations = new Dictionary<string, OpenApiOperation> | ||
{ | ||
["notify"] = new OpenApiOperation | ||
{ | ||
Summary = "Notify operation", | ||
OperationId = "notifyOp" | ||
} | ||
}, | ||
Responses = new OpenApiResponses() | ||
} | ||
} | ||
}; | ||
|
||
// Act | ||
var copy = original.CreateShallowCopy(); | ||
|
||
// Assert | ||
var originalGetOp = original.Operations![HttpMethod.Get]; | ||
var copyGetOp = copy.Operations![HttpMethod.Get]; | ||
|
||
Assert.NotNull(copyGetOp.Query); | ||
Assert.Equal("Query operation", copyGetOp.Query.Summary); | ||
Assert.Equal("queryOp", copyGetOp.Query.OperationId); | ||
|
||
Assert.NotNull(copyGetOp.AdditionalOperations); | ||
Assert.Single(copyGetOp.AdditionalOperations); | ||
Assert.Equal("Notify operation", copyGetOp.AdditionalOperations["notify"].Summary); | ||
Assert.Equal("notifyOp", copyGetOp.AdditionalOperations["notify"].OperationId); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.