How to change the "generated Servers" dropdown values
Hello,
I am having an issue as due to our environment only https calls are permitted. A proxy is handling the conversion from https to http
As the springboot project is deployed as http the generated swagger-ui points all URLs to http although it is accessed through https.
I have tried to add a new server to the OpenApi Bean in order define a HTTPS version but to no avail.
Could you please let me know how can I change the basePath so that we are using HTTPS

Thank you for the help
Hi,
You have different ways for setting serverUrl: For example:
- You can set them on the OpenAPI definition Bean
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().addServersItem(new Server().url("https://myserver.com"))
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.info(new Info().title("SpringShop API").version("V0")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
}
- You can use the @OpenAPIDefinition swagger annotation
@OpenAPIDefinition(servers = { @Server(url = "https://myserver1.com"),
@Server(url = "https://myserver2.com") }, info = @Info(title = "the title", version = "v1", description = "My API", license = @License(name = "Apache 2.0", url = "http://foo.bar"), contact = @Contact(url = "http://gigantic-server.com", name = "Fred", email = "[email protected]")))
Hi,
Thank you for taking the time to educate others.
I have tried the first approach before writing here and it does not work, the servers values do not appear to be used. I have even used the code snippet you provided above.
The end result is the same:
The second option with the annotations is working:
So perhaps there is something here, perhaps a Bug.
If needed I can try to recreate and submit a test project for you.
Thank you and have a nice weekend.
Hi,
Overriding OpenAPI Bean Definition should also work. Can you please add/upload an example, of the code that is not working ?
Hi,
I uploaded it to github at https://github.com/Azyl/springdocserverlistfrombeanissue.git
Let me know if the format is ok.
It is just the starter springboot project with springdoc and a configuration class with the OpenApi bean.
the result is:
Thanks for the help
Hi,
On your class OpenApiSwaggerConfig, just remove @OpenAPIDefinition annotation, and it should work, also while overriding OpenAPI Bean Definition :
@Configuration
public class OpenApiSwaggerConfig
How is the url generated in case the application is behind the reverse proxy? it does not takes into account the prefix path set by the proxy.
How is the url generated in case the application is behind the reverse proxy? it does not takes into account the prefix path set by the proxy.
Read the documentation.