Swashbuckle.WebApi: error opening ui

Hi, I just added the rc1 version to an aurelia app, configured startup and tried to open the ui and I see this

untitled

I suppose that the error is: An unhandled exception occurred while processing the request.

<div class="titleerror">NotSupportedException: Unbounded HTTP verbs for path 'api/Attivita/GetLatest/{last}'. Are you missing an HttpMethodAttribute?</div

but this is the declaration of the action inside the controller

    [Route("[action]/{last:int}")]
    [HttpGet("{last}")]
    public IEnumerable<UltimaAttivitaVm> GetLatest(int last)
    {

am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 1
  • Comments: 18 (2 by maintainers)

Most upvoted comments

Just figured out how to do this… By setting DocInclusionPredicate in my setup I was able to ignore methods that don’t have a specified HttpMethod.

The source code that helped me come to this conclusion: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerGen/Generator/SwaggerGenerator.cs#L84

My fix:

services.AddSwaggerGen(c =>
{
    c.DocInclusionPredicate((docName, apiDesc) =>
    {
        if (apiDesc.HttpMethod == null) return false;
        return true;
    });
});

Also important to note that I am using dotnet core sdk: 1.0.0-rc4-004771, swagger aspnetcore v1.

By doing this it also removes the need to set methods to protected assuming those methods don’t have httpMethod attributes on them.

So I had the same problem today and the resolution was simple… I had the following two GET attributes on the Controller Action:

[HttpGet]
[HttpGet("id/{id?}")]

While the first one is understandable to WebApi. It is not understandable to Swagger for some reason. I fixed the issue after changing it to this:

[HttpGet("")]
[HttpGet("id/{id?}")]

Hope this helps someone.

Came across this thread today while googling the same issue. I think if anything the error message isn’t specific enough. I realized that my issue was I had public methods in my controller that had no verb assigned… This happened as a result of my code pattern where all of my controllers inherit from a custom, intermediate base controller with some helper functions attached. I resolved the issue by making all of those methods protected instead of public.

Edit: I think the public/protected nature of non-web methods only becomes an issue where your route is defined on the controller as opposed to each method. If you put the route on the controller, all public methods are assumed by Swashbuckle to require being bound to a verb.

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.

@bsell93 's solution to add DocInclusionPredicate worked for me. Thank you.

Hi, I had the same issue. In our code this was because we had a RouteAttribute both on the controller class and on each action. The issue was solved by putting the full route on each action and removing the attribute from the class. The RouteAttribute is now also used to replace the RoutePrefixAttribute from MVC5, but this usage does not seem to be supported by Ahoy right now.