Page mentions that NSwag can be used as an alternative, and that it also generates/supports Redoc.
But there is no explanation how to do that (i.e. use redoc).
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi lonix1:
Or just add app.UseReDoc() and access via /redoc
Most simple setup for a .net core 3.0 web api project:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddSwaggerDocument(config =>
{
config.PostProcess = document =>
{
document.Info.Version = "v1";
document.Info.Title = "ToDo API";
document.Info.Description = "A simple ASP.NET Core web API";
document.Info.TermsOfService = "None";
document.Info.Contact = new NSwag.OpenApiContact
{
Name = "YourName",
Email = string.Empty,
Url = "https://twitter.com/YourName"
};
document.Info.License = new NSwag.OpenApiLicense
{
Name = "Use under LICX",
Url = "https://example.com/license"
};
};
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
#region swagger
// URLs:
// - http://localhost:65384/swagger/v1/swagger.json
// - http://localhost:65384/swagger
// - http://localhost:65384/redoc
// - http://localhost:65384/openapi
// - http://localhost:65384/openapi_redoc
//app.UseOpenApi();
app.UseSwaggerUi3();
//app.UseReDoc();
#endregion//// Add OpenAPI and Swagger middlewares to serve documents and web UIs
...
..
.
Only the following urls do not work:
// URLs:
// - http://localhost:xxxx/redoc --> This localhost page can’t be found
// - http://localhost:xxxx/openapi --> This localhost page can’t be found
// - http://localhost:xxxx/openapi_redoc --> This localhost page can’t be found
Access swagger: --> https://localhost:{YourPort}/swagger
To my knowledge, only app.UseSwaggerUI3() and app.UseReDoc() offer a web based user interface. For ReDoc, you'll need to configure the end-point.
Maybe the default route of UseReDoc is also /swagger?
Installing Swashbuckle.AspNetCore.Redoc helps regarding Redoc. The Openapi urls still don't work.
Adapted my code to look like the above.
In order to create an endpoint for Redoc, you'll need to configure it in your Startup.cs. For example:
app.UseReDoc(config =>
{
config.Path = "/redoc";
config.DocumentPath = "/swagger/v1/swagger.json";
});
EDIT
Here's another example:
https://github.com/RicoSuter/NSwag/blob/1a6c959bdb41b41f2f534d3e61a311f1cf0de6f7/src/NSwag.Sample.NETCore20/Startup.cs#L104
Moved to Master issue, check here first. #16879
Most helpful comment
Hi lonix1:
https://github.com/RicoSuter/NSwag/wiki/AspNetCore-Middleware
https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Sample.NETCore20/Startup.cs