Repository navigation
Read fragments of OpenAPI Specifications #258
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
14 commits
Select commit
Hold shift + click to select a range
c07809f
Read fragments
darrelmiller cd722e0
Code cleanup
darrelmiller e9a4946
Merge remote-tracking branch 'origin/master' into dm/read-fragment
darrelmiller 3b727ef
Update version to 1.1.0-preview.1
darrelmiller c93a9d7
Fix schema deserialization
darrelmiller 9fc169c
Fixed issue with deserializing enums in headers.
darrelmiller bed9b57
Fixed schema enum for v2 parameters
darrelmiller 893f4e2
Fixes based on PR feedback
darrelmiller 27a2ad8
More PR feedback fixes
darrelmiller b94c307
Merge pull request #261 from Microsoft/dm/fix-schema-v2
darrelmiller f3e19dd
Merge branch 'master' into dm/read-fragment
darrelmiller 2a08ff5
Fixes based on PR
darrelmiller 866c02a
Added validation to ReadFragment
darrelmiller 498f51d
Added test for path item fragment
darrelmiller 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,8 @@ public class ParsingContext | |
| /// <summary> | ||
| /// Initiates the parsing process. Not thread safe and should only be called once on a parsing context | ||
| /// </summary> | ||
| /// <param name="yamlDocument"></param> | ||
| /// <param name="diagnostic"></param> | ||
| /// <param name="yamlDocument">Yaml document to parse.</param> | ||
| /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation.</param> | ||
| /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns> | ||
| internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diagnostic) | ||
| { | ||
|
|
@@ -47,13 +47,13 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diag | |
| { | ||
| case string version when version == "2.0": | ||
| VersionService = new OpenApiV2VersionService(); | ||
| doc = this.VersionService.LoadDocument(this.RootNode); | ||
| doc = VersionService.LoadDocument(RootNode); | ||
| diagnostic.SpecificationVersion = OpenApiSpecVersion.OpenApi2_0; | ||
| break; | ||
|
|
||
| case string version when version.StartsWith("3.0"): | ||
| this.VersionService = new OpenApiV3VersionService(); | ||
| doc = this.VersionService.LoadDocument(this.RootNode); | ||
| VersionService = new OpenApiV3VersionService(); | ||
| doc = VersionService.LoadDocument(RootNode); | ||
| diagnostic.SpecificationVersion = OpenApiSpecVersion.OpenApi3_0; | ||
| break; | ||
|
|
||
|
|
@@ -64,6 +64,34 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument, OpenApiDiagnostic diag | |
| return doc; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initiates the parsing process of a fragment. Not thread safe and should only be called once on a parsing context | ||
| /// </summary> | ||
| /// <param name="yamlDocument"></param> | ||
| /// <param name="version">OpenAPI version of the fragment</param> | ||
| /// <param name="diagnostic">Diagnostic object which will return diagnostic results of the operation.</param> | ||
| /// <returns>An OpenApiDocument populated based on the passed yamlDocument </returns> | ||
| internal T ParseFragment<T>(YamlDocument yamlDocument, OpenApiSpecVersion version, OpenApiDiagnostic diagnostic) where T: IOpenApiElement | ||
| { | ||
| var node = ParseNode.Create(this, diagnostic, yamlDocument.RootNode); | ||
|
|
||
| T element = default(T); | ||
|
|
||
| switch (version) | ||
| { | ||
| case OpenApiSpecVersion.OpenApi2_0: | ||
| VersionService = new OpenApiV2VersionService(); | ||
| element = this.VersionService.LoadElement<T>(node); | ||
| break; | ||
|
|
||
| case OpenApiSpecVersion.OpenApi3_0: | ||
| this.VersionService = new OpenApiV3VersionService(); | ||
|
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.
nit, remove these "this." for consistency. |
||
| element = this.VersionService.LoadElement<T>(node); | ||
| break; | ||
| } | ||
|
|
||
| return element; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the version of the Open API document. | ||
|
|
@@ -82,20 +110,6 @@ private static string GetVersion(RootNode rootNode) | |
| return versionNode?.GetScalarValue(); | ||
| } | ||
|
|
||
| private void ComputeTags(List<OpenApiTag> tags, Func<MapNode, OpenApiTag> loadTag) | ||
| { | ||
| // Precompute the tags array so that each tag reference does not require a new deserialization. | ||
| var tagListPointer = new JsonPointer("#/tags"); | ||
|
|
||
| var tagListNode = RootNode.Find(tagListPointer); | ||
|
|
||
| if (tagListNode != null && tagListNode is ListNode) | ||
| { | ||
| var tagListNodeAsListNode = (ListNode)tagListNode; | ||
| tags.AddRange(tagListNodeAsListNode.CreateList(loadTag)); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Service providing all Version specific conversion functions | ||
| /// </summary> | ||
|
|
@@ -108,7 +122,6 @@ internal IOpenApiVersionService VersionService | |
| set | ||
| { | ||
| _versionService = value; | ||
| ComputeTags(Tags, VersionService.TagLoader); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
Can we also validate the fragment after parsing?
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 I'm not sure. I didn't think we could because of references, but as they are unresolved that shouldn't be a problem. Now I'm not sure. Will think about it some more.
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.
Added it. Seems to be fine.