Closed thiagobucca closed 6 years ago
You can change the url with the SwaggerUiRoute setting:
https://github.com/RSuter/NSwag/blob/master/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs#L19
But that parameter doesn't take "/" for an option, right?
Let's say my start url in Visual Studio is: http://localhost:54000, what i have to set in the SwaggerUiRoute to match my start url?
/ would be the correct owin path for that i think.. have you tried it?
Yes. When i set / for the path swagger loads with "Can't read from server image". That doesn't happen when my owin path is "swagger"
Here's my global.asax
`RouteTable.Routes.MapOwinPath("/", app => { app.UseSwaggerUi(typeof(WebApiApplication).Assembly, new SwaggerUiOwinSettings {
DocumentProcessors =
{
new SecurityDefinitionAppender("apikey", new SwaggerSecurityScheme
{
Type = SwaggerSecuritySchemeType.ApiKey,
Name = "token",
In = SwaggerSecurityApiKeyLocation.Header
})
},
MiddlewareBasePath = "/swagger",
});
});`
Maybe you also have to change the MiddlewareBasePath to /?
Yes, unfortunately that was my first try, i get the following error:
The path must start with a '/' followed by one or more characters. Parameter name: value
That message makes me wonder that MiddlewareBasePath doesn't take / for an option.
I have to try this with the sample project. All paths must be correct in order to make this work with owin. Cant you just simply redirect from / to /swagger?
Why not just created a redirect file, I have something like that here: http://offleaseonly.azurewebsites.net/ Is there a specific need to serve the swagger-ui on root?
No specific need, just to when we start the solution in Visual Studio, directly go to /swagger without have to type. Can i have this with a redirect file?
Sure you can, that's what I did...
Here is my fancy redirect: https://github.com/heldersepu/OffLeaseOnly/blob/master/OffLeaseOnly/index.html
Nice! Thank you for your help.
... for the record my redirect is just workaround! if someone still need to get the swagger-ui on root (not sure why anyone will need that) that issue still unsolved
Yes, i agree. I only closed because i don't know if this is really a issue, i'll let @RSuter decide.
I personally dont use global.asax based projects anymore. If this is needed for you and the “hacks” (redirect, or set startup path to /swagger) are not enough, you can try to fix it in the nswag sample project.
I too have the wish of serving wagger at the root. Having api.mydomain.com showing the documentation directly seems clean. Seems a little silly this is not an option and weird that the team does not recognize this as a need.
Hello,
Is there any way to load swagger without having to type /swagger? I mean just start the solution and go to swagger directly as the initial page.
I'm on Visual Studio 2017 and using NSwag OWIN middleware in global.asax
Thanks in advance