Add DocumentFilter after EnableSwagger has been called
See original GitHub issueI’ve got an assembly I use that provides auth, encryption, and swagger so that I don’t have to roll those things each time I stand up a new WebAPI.
Once HttpConfiguration.EnableSwagger
has been called, is there a way to add another DocumentFilter
, or is it too late at that point?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Custom DocumentFilter not being applied · Issue #1426
Specify the new Custom DocumentFilter in the SwaggerConfig (e.g. c.DocumentFilter<CustomSwaggerFilter>(); ). EXPECTED RESULT: Filters to be ...
Read more >c# - How to omit methods from Swagger documentation on ...
I have a C# ASP.NET WebAPI application with API documentation being automatically generated using Swashbuckle. I want to be able to omit certain ......
Read more >Documenting ASP.NET REST APIs with Swagger / Swashbuckle
Introduction Swagger is a way to document a REST API, and tools can automate much of this process (but not all of it)....
Read more >Swagger UI Configuration
Configuration. How to configure. Swagger UI accepts configuration parameters in four locations. From lowest to highest precedence: The swagger-config.yaml ...
Read more >Swashbuckle.WebApi
Seamlessly adds a Swagger to WebApi projects! Combines ApiExplorer and Swagger/swagger-ui to provide a rich discovery, documentation and playground ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ha! I did this morning @langdonx follow this link to the Swashbuckle API documentation and scroll to “Document Filter”. You are looking for
public class TagDescriptionsDocumentFilter : IDocumentFilter
. Add this new class to your C# project. You will need to import the following packagesusing Swashbuckle.Application; using Swashbuckle.AspNetCore.Swagger;
And although they left it out in the documentation, WHICH IS KEY, you will need to add this to your Swagger definition in the ConfigureServices method in Startup.cs in your project. See example below:
// Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.DocumentFilter<TagDescriptionsDocumentFilter>(); });
This should get you up and running! 😃
My mistake is thinking that Swagger had the information I needed when it was in the Swashbuckle documentation all along 😃
@sharrondenice I did not. 😦 Although I imagine if I were to take another crack at it, I could just send the DocumentFilters I wanted to add to the responsible assembly, and it would just inject them when appropriate.