Skip to content

Instantly share code, notes, and snippets.

@imclint21
Created July 29, 2019 02:42
Show Gist options
  • Save imclint21/5aee1c0f76a1d81ff4e16bd661964616 to your computer and use it in GitHub Desktop.
Save imclint21/5aee1c0f76a1d81ff4e16bd661964616 to your computer and use it in GitHub Desktop.
[Swashbuckle.AspNetCore] Display only ApiController controllers in the swagger
using System.Linq;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
namespace MyProgram
{
public class ApiExplorerGetsOnlyConvention : IActionModelConvention
{
public void Apply(ActionModel action)
{
action.ApiExplorer.IsVisible = action.Controller.Attributes.Any(x => x.GetType() == typeof(Microsoft.AspNetCore.Mvc.ApiControllerAttribute));
}
}
}
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options => options.Conventions.Add(new ApiExplorerGetsOnlyConvention()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment