The following action method works perfectly in ASP.NET Core and responds correctly on all http verbs (GET/POST/PUT/DELETE). However, swagger throws an exception while attempting to connect to /swagger/v1/swagger.json endpoint. The exception is
Connection id "0HKSMBFU44VRR": An unhandled exception was thrown by the application.
System.NotSupportedException: Unbounded HTTP verbs for path 'health'. Are you missing an HttpMethodAttribute?
I was able to resolve by adding the [HttpGet] attribute. However, it looks like it should not have thrown an exception?
public class HealthController
{
[Route("health")]
public IActionResult GetHealth()
{
return new OkResult();
}
}
This is by design because Swashbuckle maps one action to one Swagger "operation" which in turn maps to a single HTTP verb. This hasn't really been an issue because the typical use of Web API is to bind specific verbs to specific actions.
May I ask why you want to overload a single method in this way?
Be sure to check the controller and base class for any public methods.
I had a public method in my base class that I had to change to protected.
@aaronralls Your comment above (while old) is the only reference I can find about the protection level of methods (I am obviously missing something). I've added swashbuckle.aspnetcore to an api with only a single controller, and I get the 500 error described here if any method (in this case, there is only one method) is not protected. But if I make it protected, the documentation is blank. Are documented methods supposed to be public, and others protected?
This is the version that gives me an empty swagger doc. Changing the method to public causes the 500 error loading the swagger.json.
```csharp
[HttpGet("")]
[Route("{id}")]
protected IActionResult GetBasic(string id)
{
....
return Ok();
}
Most helpful comment
Be sure to check the controller and base class for any public methods.
I had a public method in my base class that I had to change to protected.