Best practices for Swagger UI in production

Viewed 3122

I'm working on a REST API with a Swagger UI. When it comes time to expose the API, should I expose the Swagger UI as well? If so, how would I package it into my application. Currently, I have the UI downloaded from the GitHub and am storing it in a folder alongside my project.

I'm using Go (with the Echo framework) to write the API.

1 Answers

We should not enable swagger in production due to security threats. In.net core version 6.0 version, we can protect it with the below code in Program.cs.

if(!app.Environment.IsProduction())    
{        
    app.UseSwaggerUI(c =>        
        {    
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Service");    
            c.RoutePrefix = string.Empty;  // Set Swagger UI at apps root    
        });
}
Related