-
Notifications
You must be signed in to change notification settings - Fork 197
Allow IDocument to be modified before rendering #344
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
7 commits
Select commit
Hold shift + click to select a range
d1403ba
Allow IDocument to be modified before rendering
ThomasBleijendaal 81a53b3
Removed example document filter
ThomasBleijendaal e777bd7
PR fixes
ThomasBleijendaal 593e825
Added DocumentFilter in integration test
ThomasBleijendaal 9b0133a
Added unit tests for Document + fixed integration test
ThomasBleijendaal 851c863
PR fixes
ThomasBleijendaal e02fffe
Added simple documentation to make feature more visible
ThomasBleijendaal 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
11 changes: 11 additions & 0 deletions
11
...FunctionApp.Filters/Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.Filters.csproj
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,11 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Microsoft.Azure.WebJobs.Extensions.OpenApi.Core\Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
2 changes: 1 addition & 1 deletion
2
...i.FunctionApp.InProc/Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc.csproj
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
17 changes: 17 additions & 0 deletions
17
src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Abstractions/IDocumentFilter.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,17 @@ | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions | ||
| { | ||
| /// <summary> | ||
| /// This interface allows creating custom document filters to modify the contents of the OpenApi / Swagger documentation before it is rendered. | ||
| /// </summary> | ||
| public interface IDocumentFilter | ||
| { | ||
| /// <summary> | ||
| /// This method is invoked after the <see cref="IDocument"/> has been built and just before it is rendered and returned to the client. | ||
| /// </summary> | ||
| /// <param name="request">The HTTP request.</param> | ||
| /// <param name="document">The generated document.</param> | ||
| void Apply(IHttpRequestDataObject request, OpenApiDocument document); | ||
| } | ||
| } |
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
27 changes: 27 additions & 0 deletions
27
src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Filters/DocumentFilterCollection.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,27 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions; | ||
| using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Filters | ||
| { | ||
| /// <summary> | ||
| /// This represents the collection entity for <see cref="IDocumentFilter"/> instances. | ||
| /// </summary> | ||
| public class DocumentFilterCollection | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="DocumentFilterCollection"/> class. | ||
| /// </summary> | ||
| /// <param name="documentFilters">List of <see cref="IDocumentFilter"/> instances.</param> | ||
| public DocumentFilterCollection(List<IDocumentFilter> documentFilters) | ||
| { | ||
| this.DocumentFilters = documentFilters.ThrowIfNullOrDefault(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the list of <see cref="IDocumentFilter"/> instances. | ||
| /// </summary> | ||
| public List<IDocumentFilter> DocumentFilters { get; set; } | ||
| } | ||
| } |
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
36 changes: 36 additions & 0 deletions
36
...ion/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_DocumentFilter_Tests.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,36 @@ | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using FluentAssertions; | ||
|
|
||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
|
||
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests | ||
| { | ||
| [TestClass] | ||
| [TestCategory(Constants.TestCategory)] | ||
| public class Get_DocumentFilter_Tests | ||
| { | ||
| private static HttpClient http = new HttpClient(); | ||
|
|
||
| private JObject _doc; | ||
|
|
||
| [TestInitialize] | ||
| public async Task Init() | ||
| { | ||
| var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false); | ||
| this._doc = JsonConvert.DeserializeObject<JObject>(json); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void Given_Rewritten_OpenApiDocument_Then_It_Should_Have_Modified_Description() | ||
| { | ||
| var modifiedDescription = this._doc["paths"]["/get-documentfilter"]["get"]["responses"]["200"].Value<string>("description"); | ||
|
|
||
| modifiedDescription.Should().Be("The OK response rewritten"); | ||
| } | ||
| } | ||
| } |
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
20 changes: 20 additions & 0 deletions
20
...re.WebJobs.Extensions.OpenApi.TestApp/DocumentFilters/RewriteDescriptionDocumentFilter.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,20 @@ | ||
| using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions; | ||
| using Microsoft.OpenApi.Models; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.DocumentFilters | ||
| { | ||
| internal class RewriteDescriptionDocumentFilter : IDocumentFilter | ||
| { | ||
| public void Apply(IHttpRequestDataObject request, OpenApiDocument document) | ||
| { | ||
| if (document.Paths.ContainsKey("/get-documentfilter")) | ||
| { | ||
| document | ||
| .Paths["/get-documentfilter"] | ||
| .Operations[OperationType.Get] | ||
| .Responses["200"] | ||
| .Description += " rewritten"; | ||
| } | ||
| } | ||
| } | ||
| } |
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.