Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide FileConfiguration and OutputCache controller from Swagger #989

Closed
Marusyk opened this issue Aug 13, 2019 · 5 comments
Closed

Hide FileConfiguration and OutputCache controller from Swagger #989

Marusyk opened this issue Aug 13, 2019 · 5 comments
Assignees
Labels
proposal Proposal for a new functionality in Ocelot

Comments

@Marusyk
Copy link

Marusyk commented Aug 13, 2019

Expected Behavior / New Feature

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

Actual Behavior / Motivation for New Feature

Screenshot_1

Steps to Reproduce the Problem

  1. Install-Package Ocelot -Version 13.5.2

How to hide/remove them?

@darcon77
Copy link

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));

@Marusyk
Copy link
Author

Marusyk commented Aug 15, 2019

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

@Marusyk Marusyk closed this as completed Oct 21, 2019
@joaopgrassi
Copy link

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.

@raman-m raman-m reopened this May 18, 2023
@raman-m raman-m added proposal Proposal for a new functionality in Ocelot accepted Bug or feature would be accepted as a PR or is being worked on labels Aug 28, 2023
@raman-m
Copy link
Member

raman-m commented Aug 28, 2023

@Marusyk Marusyk closed this as completed Jan 31, 2024
@raman-m raman-m removed the accepted Bug or feature would be accepted as a PR or is being worked on label Feb 1, 2024
@raman-m
Copy link
Member

raman-m commented Feb 1, 2024

Should be fixed as a part of ##1429

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal for a new functionality in Ocelot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants