Forum Discussion

vgflores's avatar
vgflores
Occasional Visitor
2 years ago

Hide a route from a method that has 2 routes

Hi everyone!

 

I want to hide a route (no show in swagger documentation). Example:

 

[Route("apirest/model/{param1}/{param2}/{param3}/{param4}")] - SHOW

[Route("apirest/model/{param1}/{param2}/{param3}/{param4}/{param5}")] – NO SHOW

public HttpResponseMessage Getvalues(string param1, string param2, string param3, double param4, string param5="")

 

Please help!!

1 Reply

  • Hi vgflores,

     

    I'm not sure what you're using to annotate your code for generation of the Swagger docs .... but if you're using something like SwashBuckle, then you could leverage it's IDocumentFilter that walks through the generated SwaggerDocument and remove certain PathItems (e.g. swaggerDoc.paths["/mypath"]) or individual operations within a path (e.g. swaggerDocs.paths["/mypath"].get = null).

    Example:

        public class FilterRoutesDocumentFilter : IDocumentFilter {
            public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) {
                swaggerDoc.paths["apirest/model/{param1}/{param2}/{param3}/{param4}/{param5}"].get = null;
            }
        }

     

    Check out what's possible in your annotation tooling.

    Kind regards,

    Frank

     


    vgflores wrote:

    Hi everyone!

     

    I want to hide a route (no show in swagger documentation). Example:

     

    [Route("apirest/model/{param1}/{param2}/{param3}/{param4}")] - SHOW

    [Route("apirest/model/{param1}/{param2}/{param3}/{param4}/{param5}")] – NO SHOW

    public HttpResponseMessage Getvalues(string param1, string param2, string param3, double param4, string param5="")

     

    Please help!!