Created
July 29, 2019 02:42
-
-
Save imclint21/5aee1c0f76a1d81ff4e16bd661964616 to your computer and use it in GitHub Desktop.
[Swashbuckle.AspNetCore] Display only ApiController controllers in the swagger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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