-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add customized document serialization support #2677
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
martincostello
merged 29 commits into
domaindrivendev:master
from
remcolam:feature/#2668-add-custom-document-serializer-support
Apr 25, 2024
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
89c445d
Added ISwaggerDocumentSerializer
c9f6721
- Fix breaking binary changes
7522848
Removed dummy test
a02dfa8
Some more code review fixes
471e800
Removed whitespaces
e40a1ca
Added some tests
082a1c4
Removed debug code
df70359
Added tests on DocumentProvider
3bf2a65
removed unused configurations
f8b6128
More code review comments resolved
dd7e74f
Fixed dunglish
90c7c4d
Fixed merge issues
bc6bf47
Fix null reference
284476f
fixed call to SwaggerMiddleware
0b46d4c
Fixed SwaggerBuilderExtensions
82985cd
Simplified TemplateBinder usage
65f2d88
Switched to using SwaggerOptions to configure the document serializer
c771dc9
Merge pull request #2 from remcolam/feature/#2668-add-custom-document…
remcolam ca28721
Update src/Swashbuckle.AspNetCore.Swagger/SwaggerOptions.cs
remcolam c5147d8
Update src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/Swagger…
remcolam 03ecdc7
review comments
144e41e
More code review items
e2048bf
Fixed comments
5c1193e
Some more tweaks
779b9d9
Update src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/Swagger…
remcolam 90a1c32
Update src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/Swagger…
remcolam 5be0578
Update src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/Swagger…
remcolam 53eba1e
Update src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/Swagger…
remcolam 04c3c32
Restored using that was needed
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
29 changes: 29 additions & 0 deletions
29
src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerOptionsExtensions.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,29 @@ | ||
| using System; | ||
| using Swashbuckle.AspNetCore.Swagger; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// Extensions for helping with configuring instances of <see cref="SwaggerOptions"/>. | ||
| /// </summary> | ||
| public static class SwaggerOptionsExtensions | ||
| { | ||
| /// <summary> | ||
| /// Sets a custom Swagger document serializer to use. | ||
| /// </summary> | ||
| /// <remarks>For the CLI tool to be able to use this, this needs to be configured for use in the service collection of your application.</remarks> | ||
| /// <typeparam name="TDocumentSerializer">The type of the custom Swagger document serializer implementation.</typeparam> | ||
| /// <param name="swaggerOptions">The options to configure the serializer for.</param> | ||
| /// <param name="constructorParameters">The parameters to pass into the constructor of the custom Swagger document serializer implementation.</param> | ||
| public static void SetCustomDocumentSerializer<TDocumentSerializer>( | ||
| this SwaggerOptions swaggerOptions, | ||
| params object[] constructorParameters) | ||
| where TDocumentSerializer : ISwaggerDocumentSerializer | ||
| { | ||
| if (swaggerOptions == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(swaggerOptions)); | ||
| } | ||
| swaggerOptions.CustomDocumentSerializer = (TDocumentSerializer)Activator.CreateInstance(typeof(TDocumentSerializer), constructorParameters); | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerServiceCollectionExtensions.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,22 @@ | ||
| using System; | ||
| using Swashbuckle.AspNetCore.Swagger; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| /// <summary> | ||
| /// Extensions to configure dependencies for Swagger. | ||
| /// </summary> | ||
| public static class SwaggerServiceCollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Configures Swagger options in the specified service collection. | ||
| /// </summary> | ||
| /// <param name="services">The service collection to configure the Swagger options for.</param> | ||
| /// <param name="setupAction">A delegate to a method to use to configure the Swagger options.</param> | ||
| public static void ConfigureSwagger( | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| this IServiceCollection services, | ||
| Action<SwaggerOptions> setupAction) | ||
| { | ||
| services.Configure(setupAction); | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
src/Swashbuckle.AspNetCore.Swagger/ISwaggerDocumentSerializer.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.OpenApi; | ||
| using Microsoft.OpenApi.Models; | ||
| using Microsoft.OpenApi.Writers; | ||
|
|
||
| namespace Swashbuckle.AspNetCore.Swagger | ||
| { | ||
| /// <summary> | ||
| /// Provide an implementation for this interface if you wish to customize how the OpenAPI document is written. | ||
| /// </summary> | ||
| public interface ISwaggerDocumentSerializer | ||
| { | ||
| /// <summary> | ||
| /// Serializes an OpenAPI document. | ||
| /// </summary> | ||
| /// <param name="document">The OpenAPI document that should be serialized.</param> | ||
| /// <param name="writer">The writer to which the document needs to be written.</param> | ||
| /// <param name="specVersion">The OpenAPI specification version to serialize as.</param> | ||
| void SerializeDocument(OpenApiDocument document, IOpenApiWriter writer, OpenApiSpecVersion specVersion); | ||
| } | ||
| } |
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
|---|---|---|
|
|
@@ -31,4 +31,4 @@ public class FilterDescriptor | |
|
|
||
| public object[] Arguments { 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
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.