Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong "Generated server url" in springdoc-openapi-ui (Swagger UI) deployed behind proxy

Spring Boot 2.2 application with springdoc-openapi-ui (Swagger UI) runs HTTP port. The application is deployed to Kubernetes with Ingress routing HTTPS requests from outside the cluster to the service.

In this case Swagger UI available at https://example.com/api/swagger-ui.html has wrong "Generated server url" - http://example.com/api. While it should be https://example.com/api.

While Swagger UI is accessed by HTTPS, the generated server URL still uses HTTP.

like image 359
Evgeniy Khyst Avatar asked Sep 06 '25 13:09

Evgeniy Khyst


2 Answers

I had same problem. Below worked for me.

@OpenAPIDefinition( 
    servers = {
       @Server(url = "/", description = "Default Server URL")
    }
) 
@SpringBootApplication
public class App {
    // ...
}
like image 113
user6070687 Avatar answered Sep 08 '25 12:09

user6070687


If the accepted solution doesn't work for you then you can always set the url manually by defining a bean.

@Bean
public OpenAPI customOpenAPI() {
    Server server = new Server();
    server.setUrl("https://example.com/api");
    return new OpenAPI().servers(List.of(server));
}

And the url can be defined via a property and injected here.

like image 29
Peter Lustig Avatar answered Sep 08 '25 10:09

Peter Lustig