linuxNoob
linuxNoob

Reputation: 720

Turn off open API specification in production environment

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

Answers (4)

Alvaro
Alvaro

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

Abd Abughazaleh
Abd Abughazaleh

Reputation: 5535

You can use :

springdoc:
  swagger-ui:
    enabled: false
  api-docs:
    enabled: false

Upvotes: 2

Bakul Kakadiya
Bakul Kakadiya

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

Nagarjuna Adapa
Nagarjuna Adapa

Reputation: 161

May be you can set the below property in prod yaml,

springdoc.api-docs.enabled=false

Upvotes: 10

Related Questions