On which environments should it be possible to access the Swagger API documentation

Viewed 13

I want to add Swagger to automatically generate the documentation for the endpoints of my API built with .NET Core 3.1.

Is there any best practice regarding the environments (testing, integration, production, etc.) where it should / should not be possible to access the Swagger documentation page? E.g. only on production, only on non-production, etc.

Technically I can easilly set it in the code like

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "AIR API (v1)");
    c.InjectStylesheet("/css/swagger/custom-swagger-ui.css", "all");
    });
}
0 Answers
Related