
alpha / beta 환경에서 swagger를 쓰고 있었습니다. 환경을 설명하자면, local 을 제외 한 도메인은 https를 쓰고 있는 상태입니다.
QA 분의 요청이 있었는데, 기타 본사의 QA에서 Postman으로 접근 하려면, 문제가 있다 보니 설정을 수정 해야 하는 문제가 불가피 했습니다. 그래서 swagger-ui에서 기타 설정을 하지 않으면, 호출시 http로 요청 되다 보니 문제가 생겼습니다.

spring doc starter를 쓰고 있었고, 위의 설정을 볼 수 있습니다.
어떻게 처리 할까 하다가, 다양한 방법을 연구하게 되었습니다.
@OpenAPIDefinition(
servers = [
Server(url = "/", description = "Default Server URL"),
Server(url = "https://seungdols-alpha.com", description = "Alpha Server URL"),
Server(url = "https://seungdols-beta.com", description = "Beta Server URL"),
]
)
@OpenAPIDefinition를 활용 하는 방법이 있습니다.
그리고, Bean으로 처리 하는 방법도 존재합니다. 그치만, 뭔가 예쁘지 않죠?
Configuration {
@Bean
@Primary
@Profile("alpha")
fun alphaOpenAPI(): OpenAPI {
return OpenAPI()
.info(
Info()
.title("API")
.description("Service API - Alpha Environment")
.version("1.0.0"),
)
.servers(
listOf(
Server()
.url("/")
.description("Current Alpha Server"),
Server()
.url("https://seungdols-alpha.com")
.description("Alpha Environment"),
),
)
}
@Bean
@Primary
@Profile("beta")
fun betaOpenAPI(): OpenAPI {
return OpenAPI()
.info(
Info()
.title("API")
.description("Service API - Beta Environment")
.version("1.0.0"),
)
.servers(
listOf(
Server()
.url("/")
.description("Current Beta Server"),
Server()
.url("https://seungdols-beta.com")
.description("Beta Environment"),
),
)
}
@Bean
@Primary
@Profile("local")
fun localOpenAPI(
@Value("\${server.port:8082}") serverPort: String,
): OpenAPI {
return OpenAPI()
.info(
Info()
.title("API")
.description("Service API - Local Development")
.version("1.0.0"),
)
.servers(
listOf(
Server()
.url("http://localhost:$serverPort")
.description("Local Development (Current)"),
),
)
}
}
하지만, 곰곰히 생각해보니 그냥 다 필요 없이 Current Path를 바라보도록 설정 해주는게 제일 편했습니다.
@OpenAPIDefinition(
servers = [
Server(url = "/", description = "Default Server URL"),
]
)
@EnableFeignClients
@SpringBootApplication
@ImportAutoConfiguration(FeignAutoConfiguration::class)
@Import(Service::class)
class ApiApplication
fun main(args: Array<String>) {
runApplication<ApiApplication>(*args)
}
application.yml 에는 기본적으로 해당 정보를 넣어주시면 됩니다.
springdoc:
api-docs:
path: /v3/api-docs
swagger-ui:
path: /swagger-ui.html
url: /v3/api-docs
참고차 남기면, swagger-ui 페이지가 캐싱 되기 때문에, 해당 설정을 변경 해도 금방 반영 되지 않으므로 캐시 삭제 후 확인 해야 한다.
반응형
'Spring > Spring 이야기' 카테고리의 다른 글
| Spring Batch와 StreamBridge 그리고 Send Message의 유실 (0) | 2025.05.22 |
|---|---|
| 스프링 핵심 원리 기본편 강의 - ComponentScan과 의존 관계 자동 주입 (1) | 2024.03.26 |
| 스프링 핵심 원리 기본편 강의 - Bean Definition (0) | 2024.03.26 |
| 스프링 핵심 원리 기본편 강의 - Bean scope & Bean lifecycle (0) | 2024.03.26 |
| 스프링 핵심 원리 기본편 강의 - 스프링 (1) | 2024.03.26 |