1

I use Springboot with swagger 3:

<!--          SWAGGER                               -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

I use a default /api prefix to all my endpoints.

This is how I configured my SwaggerConfig:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    public static final String AUTHORIZATION_HEADER = "Authorization";
    @Bean
    public Docket api() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .securityContexts(Collections.singletonList(securityContext()))
                .securitySchemes(Collections.singletonList(apiKey()))
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build().pathMapping("/api");

        return docket;
    }

    private ApiKey apiKey() {
        return new ApiKey("JWT", AUTHORIZATION_HEADER, "header");
    }
  // ......

}

When I try to access to my swagger-ui http://myhost/swagger-ui I get a popup with this message Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: asking me to define the location with.

When I enter my prefix manually : http://myhost/api then every thing is fine.

Any idea how to define my REST API prefix ?

Helen
  • 87,344
  • 17
  • 243
  • 314
medkhelifi
  • 1,071
  • 3
  • 17
  • 35
  • Hi, I had the same issue and the solution described on https://stackoverflow.com/a/53437951/924036 seems to have solved this for me. – Kaj Hejer Jan 02 '21 at 15:13

0 Answers0