티스토리 뷰

Spring

[Spring] Swagger CORS 이슈

snail voyager 2023. 11. 9. 18:44
728x90
반응형

이슈

swagger-ui.html 접속은 https 로 접속했지만

swagger에서 API 호출 시 request 는 http로 하면서 CORS 이슈 발생

Failed to fetch.
Possible Reasons:

CORS
Network Failure
URL scheme must be "http" or "https" for CORS request.

원인

https://stackoverflow.com/questions/70843940/springdoc-openapi-ui-how-do-i-set-the-request-to-https

 

springdoc-openapi-ui How do I set the request to HTTPS

When I publish, I will use HTTPS requests instead of HTTP, but swagger original URL is still HTTP, I have no idea how to set it up, and there is no documentation for servers in the original springdoc-

stackoverflow.com

조치

org.springdoc:springdoc-openapi-ui:1.7.0 으로 업그레이드해도 안됨

아래처럼 @SpringBootApplication에 추가해줘야됨

...
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
...
@OpenAPIDefinition(servers = {@Server(url = "/", description = "Default Server URL")})

@SpringBootApplication
public class MyApplication {
...
}

 

https://github.com/springdoc/springdoc-openapi/issues/726

728x90
반응형
반응형
300x250