I have problems to configure properly swagger /springdoc with Spring 6 (not Spring Boot).
I have my api exposed via /CONTEXT-PATH/api
, I managed to have swagger-ui accessible at /CONTEXT-PATH/api/swagger-ui/index.html
but it tries to get /CONTEXT-PATH/v3/api-docs/swagger-config
which doesn't exist. When I access /CONTEXT-PATH/api/v3/api-docs/swagger-config
it displays configUrl : "/CONTEXT-PATH/v3/api-docs/swagger-config"
I tried by defining properties in my application.properties
and in springdoc.config.properties
but it doesn't help:
springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.configUrl=/CONTEXT-PATH/api/v3/api-docs/swagger-config
springdoc.swagger-ui.url=/CONTEXT-PATH/api/swagger-ui/index.html
springdoc.api-docs.path=/CONTEXT-PATH/api/v3/api-docs
server.servlet.context-path=/CONTEXT-PATH
spring.mvc.servlet.path=/CONTEXT-PATH/api
And here my Java config class:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {
"mypackage.rest",
})
@PropertySource("classpath:/application.properties")
@ComponentScan(basePackages = {"org.springdoc"})
@Import({
SpringDocConfiguration.class,
SpringDocConfigProperties.class,
SpringDocSpecPropertiesConfiguration.class,
SpringDocWebMvcConfiguration.class,
MultipleOpenApiSupportConfiguration.class,
SpringDocUIConfiguration.class,
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class})
public class BoApiConfiguration implements WebMvcConfigurer {
@Autowired
private PropertiesService propertiesService;
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public GroupedOpenApi groupOpenAPI() {
return GroupedOpenApi.builder()
.group("api")
.packagesToScan("eu.europa.ec.comm.euaroundme.web.rest")
.addOpenApiCustomizer(serverOpenApiCustomizer())
.build();
}
public OpenApiCustomizer serverOpenApiCustomizer() {
String url = propertiesService.getPropertyValue(ApplicationConstants.APPLICATION_URL_PARAM_KEY);
url += "/api";
Server server = new Server().url(url).description("apiServer");
List<Server> servers = new ArrayList<>();
servers.add(server);
return openApi -> openApi.setServers(servers);
}
}
Thank you for your help
I finally managed to make it work.
The URL "/CONTEXT-PATH/api/v3/api-docs works well, I mean URL in this json file are correct.
I copied the swagger app into webapp folder and I customized swagger-initializer to set server URL