Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger .net core API ambiguous HTTP method for Action Error

Implementing Swashbuckle/Swagger with .net Core 2 API I am now receiving the 500 error when accessing swagger.json:

NotSupportedException: Ambiguous HTTP method for action - EBisAPI.Controllers._class.HandleError (EBisAPI). Actions require an explicit HttpMethod binding for Swagger

I have gone through all the controllers and see explicit routing on all the public methods of each controller. Is there a way to determine which method is throwing the ambiguous routing error?

like image 387
sammarcow Avatar asked Dec 14 '17 21:12

sammarcow


2 Answers

This can occur when a method is declared public in a controller, but without REST attributes. Changing the method to protected may address the issue.

I have seen this kind of error before and usually the error message points to the culprit: EBisAPI.Controllers._class.HandleError

I guess HandleError is a public method in your base class, right? Change it to protected and try again.

This is of course only one possible solution. If the method which is mentioned in the error message is part of an interface implementation, it doesn't work and you need to look at one of the other solutions.

like image 80
jps Avatar answered Oct 15 '22 04:10

jps


Similar to totonho's answer you can use

[ApiExplorerSettings(IgnoreApi=true)]

(From https://github.com/domaindrivendev/Swashbuckle/issues/153 )

like image 26
Michael Freidgeim Avatar answered Oct 15 '22 03:10

Michael Freidgeim