2
alper created
Support Team
Director
1 Answer(s)
-
0
To hide endpoints in Swagger, you can use
IDocumentFilter
of the Swashbuckle.class HideOrganizationUnitsFilter : IDocumentFilter { private const string pathToHide = "/identity/organization-units"; public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) { var organizationUnitPaths = swaggerDoc .Paths .Where(pathItem => pathItem.Key.Contains(pathToHide, StringComparison.OrdinalIgnoreCase)) .ToList(); foreach (var item in organizationUnitPaths) { swaggerDoc.Paths.Remove(item.Key); } } }
in
ConfigureSwaggerServices
, add this document filterprivate void ConfigureSwaggerServices(IServiceCollection services) { services.AddSwaggerGen( options => { options.SwaggerDoc("v1", new OpenApiInfo {Title = "MyProjectName API", Version = "v1"}); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); options.DocumentFilter<HideOrganizationUnitsFilter>(); //<-------- added this ----------- } ); }