RicoSuter / NSwag

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

Change path for redoc UI in OWIN Middleware #2272

Open etask-ps opened 5 years ago

etask-ps commented 5 years ago

We want to make our api available per redoc UI by changing the middlewareBasePath to 'redoc'. The settings are as follows:

RouteTable.Routes.MapOwinPath("redoc", app =>
{
    app.UseSwaggerReDoc(typeof(WebApiApplication).Assembly,
        settings
        {
            settings.MiddlewareBasePath = "/redoc";
            settings.DocumentPath = "/redoc/v1/openapi.json";
        });
});

using the app.UseSwaggerUi3() this works fine. However, when using app.UseSwaggerReDoc(), I get the following exception:

System ArgumentException
  HResult=0x80070057
  Message=The path must start with a '/' followed by one or more characters.
Parameter name: value
  Source=Microsoft.Owin
  StackTrace:
   at Microsoft.Owin.PathString..ctor(String value)
   at NSwag.AspNet.Owin.SwaggerExtensions.UseSwaggerReDoc(IAppBuilder app, IEnumerable`1 controllerTypes, Action`1 configure)
   at Etask.WebApi.WebApiApplication.<Application_Start>b__0_0(IAppBuilder app) in .\Etask.WebApi\Global.asax.cs:line 65
   at Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup)

   at Microsoft.Owin.PathString..ctor(String value)
   at NSwag.AspNet.Owin.SwaggerExtensions.UseSwaggerReDoc(IAppBuilder app, IEnumerable`1 controllerTypes, Action`1 configure)
   at Etask.WebApi.WebApiApplication.<>c.<Application_Start>b__0_0(IAppBuilder app) in .\Etask.WebApi\Global.asax.cs:line 60
   at Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup)
   at Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup)
   at System.Web.Routing.RouteCollectionExtensions.MapOwinPath(RouteCollection routes, String pathBase, Action`1 startup)
   at Etask.WebApi.WebApiApplication.Application_Start() in X:\src\Etask.Api\Etask.WebApi\Global.asax.cs:line 59

However, if I use the same settings and replace 'redoc' with 'swagger' I don't get an exception

etask-ps commented 5 years ago

i am using "x-generator": "NSwag v13.0.2.0 (NJsonSchema v10.0.20.0 (Newtonsoft.Json v12.0.0.0))"

StephanMoeller commented 4 years ago

What if you set Path = "/redoc" as well. Does it work then?

tux1337 commented 3 years ago

What if you set Path = "/redoc" as well. Does it work then?

this fixed it for me.