Reputation: 720
I saw a similar answer for Swagger 2.x
here - How do you turn off swagger-ui in production so I was wondering if there is something similar I could do for open API as well? I tried something like :
@Configuration
@Profile("!prod")
public class OpenAPIConfig
{
}
but this doesn't work. Any thoughts/suggestions?
Upvotes: 4
Views: 6125
Reputation: 140
You can try for your IsDelevopment or IsProduction
**var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();**
//For development
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.DefaultModelsExpandDepth(-1);
});
}
If you want to turn off swagger UI in production then you use this.
**var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();**
// For Production
if (app.Environment.IsProduction())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.DefaultModelsExpandDepth(-1);
});
}
Upvotes: -2
Reputation: 5535
You can use :
springdoc:
swagger-ui:
enabled: false
api-docs:
enabled: false
Upvotes: 2
Reputation: 41
Following properties can be used based on active profile
# To disable UI
springdoc.swagger-ui.enabled=false
# To disable API
springdoc.api-docs.enabled=false
Upvotes: 3
Reputation: 161
May be you can set the below property in prod yaml,
springdoc.api-docs.enabled=false
Upvotes: 10