springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.3k stars 500 forks source link

Desired Server URLs #2750

Closed AndreKremer closed 1 month ago

AndreKremer commented 1 month ago

Hello everyone I am using Spring Boot v3.2.8 with the plugin ‘springdoc-openapi-starter-webmvc-ui:2.6.0’ and I would like to list two server URL inside the dropdown bar in the Swagger UI Thanks to the well-written https://springdoc.org/#swagger-ui-properties documentation I am very close to this request Now I am facing the following problem; My application is Designed by Contract. However, for programmatic reasons, no servers are included within the corresponding yaml. Using springdoc.swagger-ui.url=/openapi.yaml the Swagger UI is generated accordingly and works fine For the provision of the server url within the dropdown bar I have tried different approaches, but all unsuccessful With the help of the documentation point 13.49. it was possible to list the desired servers in the dropdown, but the desired content using springdoc.swagger-ui.url=/openapi.yaml is ignored or overwritten In the documentation under point 13.24. I came across the CustomServerBaseUrlCustomize method, which, however, does not list the desired server urls. Now I wanted to ask where I can manually list server urls or whether this is even possible in combination with the config springdoc.swagger-ui.url=/openapi.yaml?

meridbt commented 1 month ago

@AndreKremer, you can list servers like this:


@Bean
    public OpenAPI getOpenApi() {
        return new OpenAPI()
                .info(new Info())
                .servers(List.of(
                        new Server().url("http://localhost:8081/").description("production"),
                        new Server().url("http://localhost:8082/").description("development")
                ));
    }
bnasslahsen commented 1 month ago

@meridbt,

Agree with @meridbt or see https://github.com/springdoc/springdoc-openapi/issues/89#issuecomment-533784066