question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add DocumentFilter after EnableSwagger has been called

See original GitHub issue

I’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:open
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sharrondenicecommented, Aug 2, 2018

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 packages

using 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 😃

0reactions
langdonxcommented, Aug 2, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found