swagger .net core API ambiguous HTTP Action debugging

后端 未结 7 1893
[愿得一人]
[愿得一人] 2021-02-12 10:49

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

NotSupportedException: Ambiguous HTTP

相关标签:
7条回答
  • 2021-02-12 11:20

    As i mentioned at "Swashbuckle not creating swagger.json file" :

    1. Decorate all actions with explicit Http Methods like[HttpGet("xxx")],[HttpPost("xxx")] or ... instead of [Route("xxx")].
    2. Decorate public methods in controllers with [NoAction] Attribute.
    0 讨论(0)
  • 2021-02-12 11:21

    Similar to totonho's answer you can use

    [ApiExplorerSettings(IgnoreApi=true)]
    

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

    0 讨论(0)
  • 2021-02-12 11:30

    I Had the same problem, and was because i have done the override of the Ok() method ,returning an OkObjectResult. The solution was change it from public to protected

    0 讨论(0)
  • 2021-02-12 11:33

    I tried different solutions but what it worked for me was adding the route inside the attributes as stated above. I.E: [HttpPost("yourRoute/create")] one of the issues was that I have 2 get methods so I changed their names and added the route to the attributes as I said.

    0 讨论(0)
  • 2021-02-12 11:37

    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 error before and usually the errormessage 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.

    0 讨论(0)
  • 2021-02-12 11:42

    The Clean way could be using data annotation [NonAction] instead to set your method as protected.

    0 讨论(0)
提交回复
热议问题