-
-
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
Add customized document serialization support #2677
Conversation
|
Thanks for contributing - if you'd like to continue with this pull request, please rebase against the default branch to pick up our new CI. Tests will also be required. |
437489e to
2cc25bb
Compare
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
|
I will have to look into the tests still, I always struggle with creating those, maybe I'll ask for some help from some colleagues |
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.
Looks OK to me so far, modulo a few style comments.
src/Swashbuckle.AspNetCore.Swagger/ISwaggerDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.Swagger/ISwaggerDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.Swagger/ISwaggerDocumentSerializer.cs
Outdated
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #2677 +/- ##
==========================================
- Coverage 92.13% 92.06% -0.08%
==========================================
Files 91 93 +2
Lines 3088 3111 +23
Branches 529 536 +7
==========================================
+ Hits 2845 2864 +19
- Misses 243 247 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
|
@martincostello As I am adding a test, I have the CLI test failing for me. Swashbuckle.AspNetCore.Cli.Test.ToolTests.Can_Generate_Swagger_Json() fails, because my local culture is serializing the OpenApiDouble(14.37) price example with a comma, not a period. It seems the CLI is not correctly serializing different cultures. Should I create an issue for this? (FYI, I have actually run into this myself when adding examples, and solved it by creating a SwaggerHostFactory and specifically setting the invariant culture in there) |
|
I had trouble finding good tests, I hope, the 6 I added are satisfactory. I added the fix for the culture in CLI, copied the change from the other PR. I marked the original constructors that I overloaded obsolete, I think they should be removed in the next major release, there shouldn't be multiple injection constructors, and changing the order of them breaks the DI also. (Which my test found out) |
94693e2 to
8d9cb7f
Compare
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.
Just a few minor comments.
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
|
Thanks for adding the tests too! |
src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/DocumentProvider.cs
Outdated
Show resolved
Hide resolved
|
Thanks again for your work on this - I'll merge this once/when the next planned release is intended to be 6.6.0. |
|
@martincostello I was looking at what I am trying to achieve again. I am wondering if I shouldn't change the place I am hooking in. Instead of using DI, and registering the serializer in the service provider, it could be added to SwaggerGeneratorOptions. It will prevent changing the constructor of DocumentProvider and SwaggerMiddleware. And since it's an optional serializer, it shouldn't really go via DI. But if you think, never mind, this is good enough also for other future use, that's fine |
|
Maybe have a quick look at doing that locally in your branch and see if that makes things simpler or not? My only thought is that it might make it more difficult for people to assign a custom |
|
The short answer is: you 😄 Regarding the constructor, that can be solved by things such as |
e7d4111 to
e4fc9c9
Compare
|
Fixed merge conflicts. @martincostello Take a close look at the SwaggerMiddleware.cs, where I merged the new changes from main |
|
@martincostello I abondened my idea of putting it into any of the options for obvious reasons, I fixed the call in SwaggerBuilderExtensions.cs, so I think now it should all be good |

Added support to inject a ISwaggerDocumentSerializer implementation, which can be called to manually serialize an OpenAPIDocument object.