2

I made a small spring boot application (2.2.5.RELEASE) and I want to have swagger and I use springdoc-openapi-ui version 1.6.8.

I have in my application.properties my setting "swagger-ui.hostname" which is an empty string by default.

Other settings I have for springdoc are

springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.use-root-path=false
springdoc.swagger-ui.operationsSorter=method
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=true

I can run locally the application and execute the GET endpoint test. I can see

http://localhost:8089/swagger-ui.html

( "swagger-ui.hostname" is an empty string )

I have one problem when I do deploy on tomcat server and I use

"-Dswagger-ui.hostname=company.com-live".

The problem is swagger or openapi generates url wrong for curl in the page swagger-ui.html when I execute one endpoint test (get).

I can see in the page of swagger https://company.com-live/swagger-ui.html

curl -X 'GET' \
  'https://company.com-live/api-docs/company.com-live/test' \
  -H 'accept: */*'

The app was started with "-Dswagger-ui.hostname=https://company.com-live"

( "company.com-live" is duplicated and "/api-docs" is added )

I expected this url

https://company.com-live/test

These works

https://company.com-live/internal/mon/info
https://company.com-live/ping

How to configure correct the swagger OpenAPI to obtain this url ? https://company.com-live/test

Java code for configuration is

@Configuration
@Slf4j
public class SwaggerConfig {

    @Value("${swagger-ui.hostname:}")
    private String hostname;

    @Bean
    public OpenAPI springShopOpenAPI() {

        List<Server> serversList = new ArrayList<>();

        System.out.println(message);
        log.info(message);

        if (StringUtils.isNoneBlank(hostname)) {
            serversList.add(new Server().url(hostname));
        }

        return new OpenAPI()
                .components(new Components()
                .addSecuritySchemes("basicScheme", 
                new SecurityScheme()
                    .type(SecurityScheme.Type.HTTP)
                    .scheme("basic")))
                .info(new Info()
                        .title("MyTools")
                        .description("MyTools")
                        .version("1.0.0")
                        .contact(new Contact()
                                .email("[email protected]")
                                .name("Company support"))
                .license(new License()
                    .name("Company")
                    .url("https://company.com")))
                .servers(serversList);

    }

    @Bean
    public GroupedOpenApi addressesApi() {

        return GroupedOpenApi.builder()
                .group("Test group")
                .pathsToMatch("/test/**")
                .build();
    }

    @Bean
    public GroupedOpenApi pingApi() {
        return GroupedOpenApi.builder()
                .group("Ping")
                .pathsToMatch("/ping/**")
                .build();
    }

}
0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.