I am trying to create a WebApi project with a couple of simple controllers. If I call the methods using fiddler all is fine, however I prefer to use swashbuckle as it's a bit prettier.
However, with swashbuckle installed using the default configuration it isn't working.
When I navigate to http://localhost/api/mycontroller/swagger
it redirects to http://localhost/api/mycontroller/swagger/ui/index
But then it just displays the following error:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://localhost/api/Management/swagger/ui/index'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'swagger'. </MessageDetail>
</Error>
My routing is as follows: config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
We found a very simple solution to our issue.
When swagger was added to the project it automatically updated the Bootstrapper.cs within App_Start, and it looked like this:
WebApiConfig.Register(config);
UnityConfig.Register(config, container);
SignalRConfig.Register(app, container);
SwaggerConfig.Register(config);
Simply moving swagger to the top of the list allowed it to register it's routes correctly before the web api routes:
SwaggerConfig.Register(config); // Swagger must be the first thing in this sequence or it just does not work...
WebApiConfig.Register(config);
UnityConfig.Register(config, container);
SignalRConfig.Register(app, container);
Just posting this in the hope that it helps someone else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With