This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Add predefined operationId support. #233
Open
tibortakacs
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
tibortakacs:AddPredefinedOperationIdSupport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
24 changes: 24 additions & 0 deletions
24
...ft.OpenApi.CSharpAnnotations.DocumentGeneration/Exceptions/InvalidOperationIdException.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,24 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions | ||
| { | ||
| /// <summary> | ||
| /// The exception that is recorded when it is expected to have operationId XML tag | ||
| /// but it is missing or there are more than one tags. | ||
| /// </summary> | ||
| [Serializable] | ||
| internal class InvalidOperationIdException : DocumentationException | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="InvalidOperationIdException"/>. | ||
| /// </summary> | ||
| /// <param name="message">Error message.</param> | ||
| public InvalidOperationIdException(string message = "") | ||
| : base(message) | ||
| { | ||
| } | ||
| } | ||
| } |
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
82 changes: 82 additions & 0 deletions
82
...Annotations.DocumentGeneration/PreprocessingOperationFilters/CreateOperationMetaFilter.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,82 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Xml.Linq; | ||
| using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters | ||
| { | ||
| /// <summary> | ||
| /// Filter to initialize OpenApi operation based on the annotation XML element. | ||
| /// | ||
tibortakacs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// It does not do the creation itself but forwards the call to the real generator filters. | ||
| /// The first filter which is applicable is executed in order to generate the operation. | ||
| /// </summary> | ||
| public class CreateOperationMetaFilter : IPreProcessingOperationFilter | ||
| { | ||
| private List<ICreateOperationPreProcessingOperationFilter> createOperationFilters; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new production instance of the <see cref="CreateOperationMetaFilter"/>. | ||
tibortakacs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| /// <remarks> | ||
| /// Using this constructor, the following filter list is used: | ||
| /// If the XML element contains 'operationId' tag, it is used as unique identifier | ||
| /// of the operation. Otherwise, the id is generated using the path of the operation. | ||
| /// In the latter case, multiple operation could be generated, if the path has optional | ||
| /// parameters. | ||
| /// </remarks> | ||
| public CreateOperationMetaFilter() : | ||
| this(new List<ICreateOperationPreProcessingOperationFilter> { | ||
| new UsePredefinedOperationIdFilter(), new BranchOptionalPathParametersFilter()}) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="CreateOperationMetaFilter"/>. | ||
| /// </summary> | ||
| /// <param name="createOperationFilters">List of generator filters.</param> | ||
| internal CreateOperationMetaFilter( | ||
| List<ICreateOperationPreProcessingOperationFilter> createOperationFilters) | ||
| { | ||
| this.createOperationFilters = createOperationFilters; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes the OpenApi operation based on the annotation XML element. | ||
| /// It applies the first applicable filter to create operations. | ||
| /// </summary> | ||
| /// <param name="paths">The paths to be updated.</param> | ||
| /// <param name="element">The xml element representing an operation in the annotation xml.</param> | ||
| /// <param name="settings">The operation filter settings.</param> | ||
| /// <returns>The list of generation errors, if any produced when processing the filter.</returns> | ||
| public IList<GenerationError> Apply( | ||
| OpenApiPaths paths, | ||
| XElement element, | ||
| PreProcessingOperationFilterSettings settings) | ||
| { | ||
| foreach (var filter in this.createOperationFilters) | ||
| { | ||
| if (filter.IsApplicable(element)) | ||
| { | ||
| return filter.Apply(paths, element, settings); | ||
| } | ||
| } | ||
|
|
||
| // If none of the filters could be applied --> error | ||
| return new List<GenerationError> | ||
| { | ||
| new GenerationError | ||
| { | ||
| Message = "Failed to apply any operation creation filter.", | ||
| ExceptionType = nameof(InvalidOperationException) | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...tGeneration/PreprocessingOperationFilters/ICreateOperationPreProcessingOperationFilter.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,28 @@ | ||
| // ------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
| // ------------------------------------------------------------ | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Xml.Linq; | ||
| using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models; | ||
| using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters | ||
| { | ||
| /// <summary> | ||
| /// The class representing the contract of a filter to preprocess the <see cref="OpenApiOperation"/> | ||
| /// objects in <see cref="OpenApiPaths"/> before each <see cref="OpenApiOperation"/> is processed by the | ||
| /// <see cref="IOperationFilter"/>. | ||
| /// </summary> | ||
| public interface ICreateOperationPreProcessingOperationFilter : IPreProcessingOperationFilter | ||
| { | ||
| /// <summary> | ||
| /// Verifies that the annotation XML element contains all data which are required to apply this filter. | ||
| /// </summary> | ||
| /// <param name="element">The xml element representing an operation in the annotation xml.</param> | ||
| /// <returns>True if the filter can be applied, otherwise false.</returns> | ||
| bool IsApplicable(XElement element); | ||
| } | ||
| } |
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.