filter out the APIs being documented by NSwag in ASP.NET Core MVC
See original GitHub issueI am trying to filter out the APIs being documented by NSwag inside an ASP.NET Core MVC application but it seems to be failing so far. I used the following custom IActionDescriptorCollectionProvider
which seems to be picked up by ASP.NET Core MVC but not by NSwag.
public class CustomActionDescriptorCollectionProvider : IActionDescriptorCollectionProvider
{
private readonly ActionDescriptorCollectionProvider _actionDescriptorCollectionProvider;
public CustomActionDescriptorCollectionProvider(IEnumerable<IActionDescriptorProvider> actionDescriptorProviders,
IEnumerable<IActionDescriptorChangeProvider> actionDescriptorChangeProviders)
{
if (actionDescriptorProviders == null) throw new ArgumentNullException(nameof(actionDescriptorProviders));
if (actionDescriptorChangeProviders == null) throw new ArgumentNullException(nameof(actionDescriptorChangeProviders));
_actionDescriptorCollectionProvider = new ActionDescriptorCollectionProvider(actionDescriptorProviders, actionDescriptorChangeProviders);
}
public ActionDescriptorCollection ActionDescriptors
{
get
{
var filteredCollection = _actionDescriptorCollectionProvider.ActionDescriptors.Items.Where(descriptor =>
{
return false;
}).ToList();
return new ActionDescriptorCollection(filteredCollection, _actionDescriptorCollectionProvider.ActionDescriptors.Version);
}
}
}
Then, I registered this like below:
services.AddSingleton<IActionDescriptorCollectionProvider, CustomActionDescriptorCollectionProvider>();
This is just for a sample as you can see it hides all the actions but with this I expected NSwag to document nothing.
What’s the recommended way to filter out APIs to be documented in NSwag based on a condition? I can see the SwaggerIgnoreAttribute but I cannot apply that based on a condition.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
NSwag : How can i suppress controllers ASP.NET Core
It was possible in ASP.NET MVC by "filtering" the controllers. old code: var controllers = new[] { typeof(ExternalApiController) , typeof( ...
Read more >Show only specific APIs on Swagger — Asp.Net Core
In this article, I explain how to use Document Filters on Swagger in order to control the endpoints that are being shown on...
Read more >Hide actions from Swagger / OpenAPI documentation in ...
Two approaches for hiding actions from auto-generated API documentation. ... ASP.NET MVC Core has long supported "conventions".
Read more >Enriched Web API Documentation using Swagger/OpenAPI in ...
In this article, we will learn about Web API documentation , how we can automatically generate it in ASP .NET Core and how...
Read more >Get started with NSwag and ASP.NET Core
Learn how to use NSwag to generate documentation and help pages for an ASP.NET Core web API.
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 Free
Top 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
See https://github.com/RSuter/NSwag/wiki/Middlewares
AddSwagger() is only needed for the new UseSwagger*WithApiExplorer() methods