1

I am developing a WEB API in .NET, and I want to document this with swagger. My default route is:

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

But it is giving me this error when I try to access localhost:55800/swagger:

{
  "$id": "1",
  "message": "No HTTP resource was found that matches the request URI 'http://localhost:55800/swagger/ui/index'.",
  "messageDetail": "No type was found that matches the controller named 'swagger'."
}

I've changed the swagger's route with this command:

config.EnableSwaggerUi("apihelp/{*assetPath}", c => 
    ... // following lines omitted

But I still cannot remove "api" prefix from my routeTemplate in the MapHttpRoute method.

How can I make it recognize the route without this "api" prefix on MapHttpRoute?

William
  • 502
  • 1
  • 9
  • 27
  • Your Web API is snagging the route before it gets to Swagger. Have you thought about changing your route to begin with a segment? Such as `"api/{controller}/{action}/{id}"`? – mason Mar 15 '18 at 20:48
  • Yes, I have tried to change the route template with `api` prefix, but there is a way to make it work without the `api` prefix? – William Mar 15 '18 at 20:52
  • pls. check if [this answer](https://stackoverflow.com/questions/45857289/unable-to-change-swagger-ui-path/45859693#45859693) helps. – jps Mar 16 '18 at 08:22
  • @jps It is very interesting, I could make a custom route to my swagger, but it still giving me problems if I do not put the prefix `api` to routes. – William Mar 16 '18 at 12:52
  • so you made some progress after reading my answer? Then pls. edit your question so that we see what changed and what's the current problem. – jps Mar 16 '18 at 13:03

0 Answers0