RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

Web api : Use API base URL for swaggerUI URL ? #1863

Closed KumG closed 5 years ago

KumG commented 5 years ago

Hello,

I have a Web API project and I'm using the Owin middleware :

RouteTable.Routes.MapOwinPath("swagger", app =>
{
    app.UseSwaggerUi3(typeof(MyProject).Assembly, s =>
    {
      s.GeneratorSettings.Title = "MyAPI";
      s.MiddlewareBasePath = "/swagger";
    });
});

SwaggerUI is then accessible with the URL "http://localhost/myproject/swagger/index.html" and the swagger file with "http://localhost/myproject/swagger/v1/swagger.json ". The base URL is "localhost/myproject" and my methods are like "/api/persons"

Instead, I would like to use the URL "http://localhost/myproject/api/index.html" for the swaggerUI.

Is it possible ?

I tried to follow this guide but I use the path "api" :

<add name="NSwag" path="api" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

The swagger UI is at the good URL but my API doesnt work anymore.

KumG commented 5 years ago

I finally used the Owin Startup class with "s.SwaggerUiRoute = "/api";"