I do not need to display FileConfigurationController and OutputCacheController in my swagger of API Geteway.

How to hide/remove them?
Implement custom API Explorer like so:
public class FilteredApiExplorer : IApiExplorer
{
public Collection<ApiDescription> ApiDescriptions { get; }
public FilteredApiExplorer(IApiExplorer explorer)
{
ApiDescriptions = new Collection<ApiDescription>(explorer.ApiDescriptions.Where(d => !d.ActionDescriptor.ControllerDescriptor.ControllerType.FullName.Contains("FileConfigurationController")).ToList());
}
}
Then replace the instance of IApiExplorer class in DI container with the custom one:
Services.Replace(typeof(IApiExplorer), new FilteredApiExplorer(apiExplorer));
Thanks @darcon77,
I know how to do it in swagger, but I hope that there are some setting in Ocelot for this.
For now I've solved it in this way
internal class HideOcelotControllersFilter : IDocumentFilter
{
private static readonly string[] _ignoredPaths = {
"/configuration",
"/outputcache/{region}"
};
public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
{
foreach(var ignorePath in _ignoredPaths)
{
swaggerDoc.Paths.Remove(ignorePath);
}
}
}
then
services.AddSwaggerGen(cfg =>
{
cfg.DocumentFilter<HideOcelotControllersFilter>();
});
it's tricky, I'm looking for another way
I think this shouldn't be closed. Both solutions above work but are not ideal. In essence, unless necessary I think Ocelot should hide these controllers from being "discovered" by things like Swashbuckle.
I didn't have time to look into the code, but just adding [ApiExplorerSettings(IgnoreApi=true)] should do the job.
Most helpful comment
I think this shouldn't be closed. Both solutions above work but are not ideal. In essence, unless necessary I think Ocelot should hide these controllers from being "discovered" by things like Swashbuckle.
I didn't have time to look into the code, but just adding
[ApiExplorerSettings(IgnoreApi=true)]should do the job.