Recently I've moved from SpringFox 2 to Springdoc + OpenAPI 3. It's a bit faster and it works perfectly in my local environment.
When I try to use it in the production environment, the Swagger UI page opens fine. The problem is when I hit the API endpoint, Swagger UI shows this error message:
The error in the browser console is:
Mixed Content: The page at 'https://<myproductionUrl>/swagger-ui/index.html#/Ravel/getLabelFormats' was loaded over HTTPS, but requested an insecure resource 'http://<myproductionAPIUrl>/labels?language=10&includeData=false'. This request has been blocked; the content must be served over HTTPS.
I enabled CORS in my Spring Boot project:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
This is my Pom file:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-annotations -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.swagger.core.v3/swagger-models -->
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-models</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.79.Final</version>
</dependency>
My application.yml
file configuration:
springdoc:
swagger-ui:
enabled: true
disable-swagger-default-url: true
api-docs:
path: /v3/api-docs
Java 8
Spring Boot 2.7.8
I don't know what configuration I've forgot. Can someone orient me?