1

I'm trying to limit what shows up on swagger by limiting the routes available. Here are my current routes:

config.Routes.MapHttpRoute(
    name: "SiteCache",
    routeTemplate: "{controller}/{id}/{action}",
    defaults: new {
        controller = "Sites",
        action ="Cache"
    },
    constraints: new {
        httpMethod = new HttpMethodConstraint(HttpMethod.Delete),
        controller = "Sites"
    }
);

config.Routes.MapHttpRoute(
    name: "SitePost",
    routeTemplate: "{controller}",
    defaults: new {
        controller = "Sites",
        action ="Post"
    },
    constraints: new
    {
        httpMethod = new HttpMethodConstraint(HttpMethod.Post),
        controller = "Sites"
    }
);

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "{controller}/{id}",
    defaults: new { id = RouteParameter.Optional },
    constraints: new
    {
        controller = @"^(?:(?!Sites).)*$"
    }
);

That got rid of a couple routes I wanted to remove but I have two left that I'm trying to remove.

enter image description here

For the two with arrows in the image above, they are the same as the ones above them. I'm not sure why there is a redundancy here but I'd really like to get rid of the ones with the arrows.

What confuses me is I don't have the id as optional in Sites/{id}/Cache so why is that one even showing up.

The methods look like this:

[HttpDelete]
public ResponseMessage<Result> Cache([FromUri] string id)
{

[HttpPost]
public ResponseMessage<Result> Post(Site mainObj, [FromUri] string authKey)
{
Lauren Rutledge
  • 1,195
  • 5
  • 18
  • 27
jcaruso
  • 2,364
  • 1
  • 31
  • 64
  • Check [this](https://stackoverflow.com/a/40432458/8215147) or [this](https://stackoverflow.com/a/41624105/8215147) posts, I think that they may help you :) – Rui Fernandes Aug 16 '18 at 15:10
  • @RuiFernandes adding the attribute `[ApiExplorerSettings(IgnoreApi = true)]` to my methods will remove all of them from the documentation, so that doesn't help and I'm afraid swaggers restriction attribute will do the same. These two methods are generating two endpoints each in the documentation, I'm looking to remove those duplicates. What you've given me will remove them all. – jcaruso Aug 16 '18 at 15:53
  • Oh ok @jcaruso, I hadn't noticed it. My bad, sorry. – Rui Fernandes Aug 16 '18 at 16:18
  • Hello again :) see [this](https://stackoverflow.com/questions/39843269/asp-net-web-api-swagger-swashbuckle-duplicate-operationid) now, it seems the same problem that you're facing and it was solved :) – Rui Fernandes Aug 16 '18 at 16:19
  • @RuiFernandes I was able to use his solution, but it didn't work for me since I wanted the route to be the top delete instead I'm left with the bottom one. – jcaruso Aug 16 '18 at 16:56
  • Try with IDocument filter, with that you can Add/Remove anything from the swagger document that ultimately controls what is shown in the UI – Helder Sepulveda Aug 16 '18 at 18:23
  • @HelderSepu isn't the XML build at build time and placed into the bin directory? – jcaruso Aug 16 '18 at 19:16
  • XML build !?!? are we talking about the same thing here? ... the swagger document also known as swagger.json looks like this: http://swagger-net-test.azurewebsites.net/swagger/docs/V1 ... that is generated at runtime – Helder Sepulveda Aug 16 '18 at 19:46
  • @HelderSepu I thought it was generated at build and placed into the `bin\SwaggerApi.XML`as output. – jcaruso Aug 16 '18 at 20:06
  • No that Xml is something else, that is from your project not from swagger or swashbuckle – Helder Sepulveda Aug 16 '18 at 20:10
  • Take a look at your SwaggerConfig for DocumentFilter https://github.com/heldersepu/Swagger-Net-Test/blob/master/Swagger_Test/App_Start/SwaggerConfig.cs#L195 – Helder Sepulveda Aug 16 '18 at 20:13

0 Answers0