Repository navigation
Fix V2 parameter deserializer to recognize formData instead of form #155
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
PerthCharern
merged 6 commits into
master
from
PerthCharern/FixFormToFormDataAndAddBasicUnitTests
Dec 19, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c9ee09
- V2 doc parameter in can be "formData", not just "form".
PerthCharern 5aa1dc8
- Add TestHelper and move redundant code there
PerthCharern 40d1924
Style changes
PerthCharern 3239b8d
Merge branch 'master' into PerthCharern/FixFormToFormDataAndAddBasicU…
PerthCharern 9b70654
Merge branch 'master' into PerthCharern/FixFormToFormDataAndAddBasicU…
PerthCharern 05d3959
Merge branch 'master' into PerthCharern/FixFormToFormDataAndAddBasicU…
PerthCharern 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.IO; | ||
| using System.Linq; | ||
| using Microsoft.OpenApi.Readers.ParseNodes; | ||
| using SharpYaml.Serialization; | ||
|
|
||
| namespace Microsoft.OpenApi.Readers.Tests | ||
| { | ||
| internal class TestHelper | ||
| { | ||
| public static MapNode CreateYamlMapNode(Stream stream) | ||
| { | ||
| var yamlStream = new YamlStream(); | ||
| yamlStream.Load(new StreamReader(stream)); | ||
| var yamlNode = yamlStream.Documents.First().RootNode; | ||
|
|
||
| var context = new ParsingContext(); | ||
| var diagnostic = new OpenApiDiagnostic(); | ||
|
|
||
| return new MapNode(context, diagnostic, (YamlMappingNode)yamlNode); | ||
| } | ||
| } | ||
| } |
152 changes: 152 additions & 0 deletions
152
test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.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,152 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.IO; | ||
| using FluentAssertions; | ||
| using Microsoft.OpenApi.Models; | ||
| using Microsoft.OpenApi.Readers.ParseNodes; | ||
| using Microsoft.OpenApi.Readers.V2; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.OpenApi.Readers.Tests.V2Tests | ||
| { | ||
| [Collection("DefaultSettings")] | ||
| public class OpenApiParameterTests | ||
| { | ||
| private const string SampleFolderPath = "V2Tests/Samples/OpenApiParameter"; | ||
|
|
||
| [Fact] | ||
| public void ParseBodyParameterShouldSucceed() | ||
| { | ||
| // Arrange | ||
| MapNode node; | ||
| using (var stream = File.OpenRead(Path.Combine(SampleFolderPath, "bodyParameter.yaml"))) | ||
| { | ||
| node = TestHelper.CreateYamlMapNode(stream); | ||
| } | ||
|
|
||
| // Act | ||
| var parameter = OpenApiV2Deserializer.LoadParameter(node); | ||
|
|
||
| // Assert | ||
| // Body parameter is currently not translated via LoadParameter. | ||
| // This design may be revisited and this unit test may likely change. | ||
| parameter.ShouldBeEquivalentTo(null); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ParsePathParameterShouldSucceed() | ||
| { | ||
| // Arrange | ||
| MapNode node; | ||
| using (var stream = File.OpenRead(Path.Combine(SampleFolderPath, "pathParameter.yaml"))) | ||
| { | ||
| node = TestHelper.CreateYamlMapNode(stream); | ||
| } | ||
|
|
||
| // Act | ||
| var parameter = OpenApiV2Deserializer.LoadParameter(node); | ||
|
|
||
| // Assert | ||
| parameter.ShouldBeEquivalentTo( | ||
| new OpenApiParameter | ||
| { | ||
| In = ParameterLocation.Path, | ||
| Name = "username", | ||
| Description = "username to fetch", | ||
| Required = true, | ||
| Schema = new OpenApiSchema | ||
| { | ||
| Type = "string" | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ParseQueryParameterShouldSucceed() | ||
| { | ||
| // Arrange | ||
| MapNode node; | ||
| using (var stream = File.OpenRead(Path.Combine(SampleFolderPath, "queryParameter.yaml"))) | ||
| { | ||
| node = TestHelper.CreateYamlMapNode(stream); | ||
| } | ||
|
|
||
| // Act | ||
| var parameter = OpenApiV2Deserializer.LoadParameter(node); | ||
|
|
||
| // Assert | ||
| parameter.ShouldBeEquivalentTo( | ||
| new OpenApiParameter | ||
| { | ||
| In = ParameterLocation.Query, | ||
| Name = "id", | ||
| Description = "ID of the object to fetch", | ||
| Required = false, | ||
| Schema = new OpenApiSchema | ||
| { | ||
| Type = "array", | ||
| Items = new OpenApiSchema | ||
| { | ||
| Type = "string" | ||
| } | ||
| }, | ||
| Style = ParameterStyle.Form, | ||
| Explode = true | ||
| }); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ParseFormDataParameterShouldSucceed() | ||
| { | ||
| // Arrange | ||
| MapNode node; | ||
| using (var stream = File.OpenRead(Path.Combine(SampleFolderPath, "formDataParameter.yaml"))) | ||
| { | ||
| node = TestHelper.CreateYamlMapNode(stream); | ||
| } | ||
|
|
||
| // Act | ||
| var parameter = OpenApiV2Deserializer.LoadParameter(node); | ||
|
|
||
| // Assert | ||
| // Form data parameter is currently not translated via LoadParameter. | ||
| // This design may be revisited and this unit test may likely change. | ||
| parameter.ShouldBeEquivalentTo(null); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ParseHeaderParameterShouldSucceed() | ||
| { | ||
| // Arrange | ||
| MapNode node; | ||
| using (var stream = File.OpenRead(Path.Combine(SampleFolderPath, "headerParameter.yaml"))) | ||
| { | ||
| node = TestHelper.CreateYamlMapNode(stream); | ||
| } | ||
|
|
||
| // Act | ||
| var parameter = OpenApiV2Deserializer.LoadParameter(node); | ||
|
|
||
| // Assert | ||
| parameter.ShouldBeEquivalentTo( | ||
| new OpenApiParameter | ||
| { | ||
| In = ParameterLocation.Header, | ||
| Name = "token", | ||
| Description = "token to be passed as a header", | ||
| Required = true, | ||
| Style = ParameterStyle.Simple, | ||
| Schema = new OpenApiSchema | ||
| { | ||
| Type = "array", | ||
| Items = new OpenApiSchema | ||
| { | ||
| Type = "integer", | ||
| Format = "int64" | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiParameter/bodyParameter.yaml
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,9 @@ | ||
| # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject | ||
| name: user | ||
| in: body | ||
| description: user to add to the system | ||
| required: true | ||
| schema: | ||
| type: array | ||
| items: | ||
| type: string |
6 changes: 6 additions & 0 deletions
6
test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiParameter/formDataParameter.yaml
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,6 @@ | ||
| # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject | ||
| name: avatar | ||
| in: formData | ||
| description: The avatar of the user | ||
| required: true | ||
| type: file |
10 changes: 10 additions & 0 deletions
10
test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiParameter/headerParameter.yaml
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,10 @@ | ||
| # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we include this line?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should point to the source we took the YAML files from. |
||
| name: token | ||
| in: header | ||
| description: token to be passed as a header | ||
| required: true | ||
| type: array | ||
| items: | ||
| type: integer | ||
| format: int64 | ||
| collectionFormat: csv | ||
6 changes: 6 additions & 0 deletions
6
test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiParameter/pathParameter.yaml
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,6 @@ | ||
| # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject | ||
| name: username | ||
| in: path | ||
| description: username to fetch | ||
| required: true | ||
| type: string |
9 changes: 9 additions & 0 deletions
9
test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiParameter/queryParameter.yaml
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,9 @@ | ||
| # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject | ||
| name: id | ||
| in: query | ||
| description: ID of the object to fetch | ||
| required: false | ||
| type: array | ||
| items: | ||
| type: string | ||
| collectionFormat: multi |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we embed this files with the test.dll?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the pros and cons of this. Darrel (@darrelmiller) also pointed this out earlier.
What's the disadvantage of not embedding a test file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PerthCharern It just means you have to carry those files around to make the tests work. If they are embedded in the DLL then the tests are self-contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand the concerns now. At first I thought using a non-embedded resource with relative path should work, but that might not be the case since the test assembly can technically be run from anywhere.
Let's make this change in a separate PR for all resources.