Swashbuckle.webapi: Ignore method to prevent swagger doc failure

Created on 2 Dec 2015  路  3Comments  路  Source: domaindrivendev/Swashbuckle.WebApi

I have an interesting problem. My team and I are working on code that have ambiguous routes which causes swashbuckle to break (rightfully so).
ex. Multiple operations with path and method POST is not supported.

Although we need to fix this problem, it is going to be a large undertaking due to the fact that it will require our API contract to change and the company is not going to be too keen on that idea.

SO... I still want to use Swashbuckle to generate Swagger docs and Swagger UI. I want to do this without refactoring my endpoints.

==So my question is==
Is there a way to [SwaggerIgnore] a method that is causing the issue and have Swashbuckle generate the json / UI by excluding that method with SwaggerIgnore on it?

I want the following to work:

[HttpPost, Route("Whatever")]
public HttpResponseMessage DoSomething(...) { ... }

[SwaggerIgnore] // because removing this from swagger doc gen will fix my issue
[HttpPost, Route("Whatever")]
public HttpResponseMessage DoSomethingElse(...) { ... }

I hope this makes sense. Looking forward to some ideas.
Thanks!

Most helpful comment

Right after I posted this I found this. I am going to try it and if it works I will close this issue.

[ApiExplorerSettings(IgnoreApi = true)]

All 3 comments

Right after I posted this I found this. I am going to try it and if it works I will close this issue.

[ApiExplorerSettings(IgnoreApi = true)]

This did the trick.

Yep that worked, when attaching an Abstract class to my controller, this may help someone else

public abstract class AuthorizedRequest : Controller { [ApiExplorerSettings(IgnoreApi = true)] public string GetUserID() { return this.User.Claims.First(i => i.Type == "userId").Value; } }

Was this page helpful?
0 / 5 - 0 ratings