14

When I access to the swagger url: http://localhost:28483/swagger/ui/index, it generates this error:

500 : undefined http://localhost:28483/swagger/docs/v1

Any ideas?

UPDATED: See this detail error in firebug:

Not supported by Swagger 2.0: Multiple operations
 with path 'api/BimModel' and method 'GET'. See the config setting - \"ResolveConflictingActions\" for
 a potential workaround
2
  • what's error you got? Commented Oct 6, 2015 at 15:28
  • @CuongLe: That's everything I got in the browser. Commented Oct 6, 2015 at 15:51

7 Answers 7

11

Swagger might be considering two actions as one operation (like in the case of this common scenario)...

GET api/Products
GET api/Products/{id}

It seems you can use attribute routing to fix this and use these attributes above your actions so swagger will recognize them separately.

[Route("api/Products")]

[Route("api/Products/{id:guid}")]
Sign up to request clarification or add additional context in comments.

Comments

9

Have you tried enable this in you swagger config?

c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());

1 Comment

While this probably resolves the error, the other actions won't show up then in swagger.
1

In the controller, it got two different GET operations and it is disallowed by Swagger. I suggest to either have only single GET operation for each controller or modify the router in WebApiConfig

1 Comment

Unfortunately modification of the router in ApiConfig does not helps. Still got Not supported by Swagger 2.0: Multiple operations with path.... It looks like I have to create new controller for each get method or is there any other way how to force swagger to cooperate (some attributes,...)?
0

I had the same issue when mixing attribute routing with default routes. When I removed the default route the problem went away. The downside is, without the default route defined, I had to add attribute routing to all my controllers.

So from my WebApiConfig I removed:

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "{controller}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

And added attribute routing to my controller:

[Route("Session")] // Added this attribute
public async Task<IHttpActionResult> Get()
...    
[Route("Session/{id}")] // Added this attribute
public async Task<IHttpActionResult> Get(int id)

In reality I use a [RoutePrefix("Session")] on my Controller and use [Route("")] on my methods, but the result should be the same.

Comments

0

I was getting this error due to the parameter names not matching between the Attribute Routing statement and the method signature.

[HttpGet("{id}")]
public IActionResult Get(string deviceNumber){
...

After changing "{id}" to "{deviceNumber}" it fixed the error.

Comments

0

In my case, the error resulted from a duplicate http attribute:

[HttpPost("PostCustomer")]
public async Task<IActionResult> PostCustomer([FromBody] Customer cust)

We were in the process of creating a new version of the endpoint, so I copied and pasted the old method, renaming the function name and forgot to rename the attribute:

[HttpPost("PostCustomer")] // Duplicate attribute maps to above method
public async Task<IActionResult> CreateNewCustomer([FromBody] Customer2 cust)

Once the second attribute was renamed to the new method, Swagger was fine again.

Comments

-1
config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "api/{controller}/{action}/{id}",
    defaults: new { id = RouteParameter.Optional }
);

1 Comment

Hey and welcome to Stackoverflow! Please use English, as hardly anybody will be able to understand your answer. The idea of this site is that one person asks a question, another person answers it and the solution for the problem in question is documented for everybody with the same problem. So, if only a fraction of people understand your answer, it is kind of a waste ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.