-
Notifications
You must be signed in to change notification settings - Fork 279
Add filterByOperationId command option #636
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
31 commits
Select commit
Hold shift + click to select a range
0dc267c
Add a mock OpenApiDocument
MaggieKimani1 0ecca08
Add tests for filtering validation
MaggieKimani1 2f4a1c8
Add an OpenApi filtering service for filtering an OpenApiDocument bas…
MaggieKimani1 8e45f8b
Add necessary packages
MaggieKimani1 f270b90
Simplify using statement and switch condition
MaggieKimani1 9cda4fb
Use static class reference
MaggieKimani1 af61c14
Add --filterbyOperationId command option
MaggieKimani1 d24442d
Add filterByOperationId param and logic
MaggieKimani1 501e88c
Add static modifier
MaggieKimani1 d5b1b5e
Clean up and add xml comments
MaggieKimani1 4016ba1
Add a class that visits the OpenApi operations and returns the search…
MaggieKimani1 73bef22
Add a search result object model
MaggieKimani1 a1d46e5
Copies OpenApiOperation references to the new subset document
MaggieKimani1 b3c79eb
Copy OpenApiInfo and components from the source document to the new s…
MaggieKimani1 cd5f3fa
Add an info object to the mock document
MaggieKimani1 3c43ea1
Clean up: Remove unnecessary params
MaggieKimani1 43f48ec
Remove package reference
MaggieKimani1 8ba33cd
Revert "Remove package reference"
MaggieKimani1 2397e9d
Update the Public API interface text file
MaggieKimani1 d13dcf4
Remove unnecessary package dependency
MaggieKimani1 00dd9c4
Allow filtering for multiple operationIds
MaggieKimani1 3f3dae0
Add check for writing to an already existing file
MaggieKimani1 27ab7f7
Copy over all Info properties
MaggieKimani1 c3c0abc
Add license header
MaggieKimani1 dbd8d92
Clean up and add XML documentations for public methods
MaggieKimani1 a689c36
Copy over extensions object to new document
MaggieKimani1 deaa2fe
Move declaration closer to first reference point
MaggieKimani1 015b3cd
Code cleanup
MaggieKimani1 ac94489
Merge branch 'vnext' into mk/add-filter-commandOption
darrelmiller d259cc1
Remove [Fact] attribute
MaggieKimani1 f2102cc
Merge remote-tracking branch 'origin/mk/add-filter-commandOption' int…
MaggieKimani1 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,112 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using Microsoft.OpenApi.Interfaces; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.OpenApi.Services | ||
| { | ||
| internal class CopyReferences : OpenApiVisitorBase | ||
| { | ||
| private readonly OpenApiDocument _target; | ||
| public OpenApiComponents Components = new(); | ||
|
|
||
| public CopyReferences(OpenApiDocument target) | ||
| { | ||
| _target = target; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Visits IOpenApiReferenceable instances that are references and not in components. | ||
| /// </summary> | ||
| /// <param name="referenceable"> An IOpenApiReferenceable object.</param> | ||
| public override void Visit(IOpenApiReferenceable referenceable) | ||
MaggieKimani1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| switch (referenceable) | ||
| { | ||
| case OpenApiSchema schema: | ||
| EnsureComponentsExists(); | ||
| EnsureSchemasExists(); | ||
| if (!Components.Schemas.ContainsKey(schema.Reference.Id)) | ||
| { | ||
| Components.Schemas.Add(schema.Reference.Id, schema); | ||
| } | ||
| break; | ||
|
|
||
| case OpenApiParameter parameter: | ||
| EnsureComponentsExists(); | ||
| EnsureParametersExists(); | ||
| if (!Components.Parameters.ContainsKey(parameter.Reference.Id)) | ||
| { | ||
| Components.Parameters.Add(parameter.Reference.Id, parameter); | ||
| } | ||
| break; | ||
|
|
||
| case OpenApiResponse response: | ||
| EnsureComponentsExists(); | ||
| EnsureResponsesExists(); | ||
| if (!Components.Responses.ContainsKey(response.Reference.Id)) | ||
| { | ||
| Components.Responses.Add(response.Reference.Id, response); | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| break; | ||
| } | ||
| base.Visit(referenceable); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Visits <see cref="OpenApiSchema"/> | ||
| /// </summary> | ||
| /// <param name="schema">The OpenApiSchema to be visited.</param> | ||
| public override void Visit(OpenApiSchema schema) | ||
| { | ||
| // This is needed to handle schemas used in Responses in components | ||
| if (schema.Reference != null) | ||
| { | ||
| EnsureComponentsExists(); | ||
| EnsureSchemasExists(); | ||
| if (!Components.Schemas.ContainsKey(schema.Reference.Id)) | ||
| { | ||
| Components.Schemas.Add(schema.Reference.Id, schema); | ||
| } | ||
| } | ||
| base.Visit(schema); | ||
| } | ||
|
|
||
| private void EnsureComponentsExists() | ||
| { | ||
| if (_target.Components == null) | ||
| { | ||
| _target.Components = new OpenApiComponents(); | ||
| } | ||
| } | ||
|
|
||
| private void EnsureSchemasExists() | ||
| { | ||
| if (_target.Components.Schemas == null) | ||
| { | ||
| _target.Components.Schemas = new Dictionary<string, OpenApiSchema>(); | ||
| } | ||
| } | ||
|
|
||
| private void EnsureParametersExists() | ||
| { | ||
| if (_target.Components.Parameters == null) | ||
| { | ||
| _target.Components.Parameters = new Dictionary<string, OpenApiParameter>(); | ||
| } | ||
| } | ||
|
|
||
| private void EnsureResponsesExists() | ||
| { | ||
| if (_target.Components.Responses == null) | ||
| { | ||
| _target.Components.Responses = new Dictionary<string, OpenApiResponse>(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.