Repository navigation
Add deserializers and restructure the Reader unit tests #113
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 all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a2337db
- Add deserializer for Discriminator, Xml, Encoding
PerthCharern 84fddba
- Modify / Rewrite majority of V3 reader tests
PerthCharern 5bc9159
Clean up csproj
PerthCharern 72959fd
- Add reader v3 tests for discriminator and xml
PerthCharern 09b7e20
- add v3 test for Encoding
PerthCharern 425003a
- Add V2 and V3 reader tests for Security Scheme
PerthCharern 550c2b4
- Add V3 Reader tests for Schema
PerthCharern 8a611d8
Add comment to explain the fixture
PerthCharern 2c262ae
Merge branch 'master' into PerthCharern/UpdateV2Reader
PerthCharern f25e04d
Remove the old file V2Tests
PerthCharern 4d25aba
Remove ParameterTests since serialization of parameter based on explo…
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
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
73 changes: 73 additions & 0 deletions
73
src/Microsoft.OpenApi.Readers/V2/OpenApiXmlDeserializer.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,73 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| using System; | ||
| using Microsoft.OpenApi.Any; | ||
| using Microsoft.OpenApi.Extensions; | ||
| using Microsoft.OpenApi.Models; | ||
| using Microsoft.OpenApi.Readers.ParseNodes; | ||
|
|
||
| namespace Microsoft.OpenApi.Readers.V2 | ||
| { | ||
| /// <summary> | ||
| /// Class containing logic to deserialize Open API V3 document into | ||
|
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. Will fix comment to V2 |
||
| /// runtime Open API object model. | ||
| /// </summary> | ||
| internal static partial class OpenApiV2Deserializer | ||
| { | ||
| private static readonly FixedFieldMap<OpenApiXml> XmlFixedFields = new FixedFieldMap<OpenApiXml> | ||
| { | ||
| { | ||
| "name", (o, n) => | ||
| { | ||
| o.Name = n.GetScalarValue(); | ||
| } | ||
| }, | ||
| { | ||
| "namespace", (o, n) => | ||
| { | ||
| o.Namespace = new Uri(n.GetScalarValue()); | ||
| } | ||
| }, | ||
| { | ||
| "prefix", (o, n) => | ||
| { | ||
| o.Prefix = n.GetScalarValue(); | ||
| } | ||
| }, | ||
| { | ||
| "attribute", (o, n) => | ||
| { | ||
| o.Attribute = bool.Parse(n.GetScalarValue()); | ||
| } | ||
| }, | ||
| { | ||
| "wrapped", (o, n) => | ||
| { | ||
| o.Wrapped = bool.Parse(n.GetScalarValue()); | ||
| } | ||
| }, | ||
| }; | ||
|
|
||
| private static readonly PatternFieldMap<OpenApiXml> XmlPatternFields = | ||
| new PatternFieldMap<OpenApiXml> | ||
| { | ||
| {s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, n.CreateAny())} | ||
| }; | ||
|
|
||
| public static OpenApiXml LoadXml(ParseNode node) | ||
| { | ||
| var mapNode = node.CheckMapNode("xml"); | ||
|
|
||
| var xml = new OpenApiXml(); | ||
| foreach (var property in mapNode) | ||
| { | ||
| property.ParseField(xml, XmlFixedFields, XmlPatternFields); | ||
| } | ||
|
|
||
| return xml; | ||
| } | ||
| } | ||
| } | ||
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.
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.
nit, consider a switch statement
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'll make this fix with a future PR.