78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
package com.kamco.cd.kamcoback.config;
|
|
|
|
import io.swagger.v3.oas.models.Components;
|
|
import io.swagger.v3.oas.models.OpenAPI;
|
|
import io.swagger.v3.oas.models.info.Info;
|
|
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
|
import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
import io.swagger.v3.oas.models.servers.Server;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
@Configuration
|
|
public class OpenApiConfig {
|
|
|
|
@Value("${server.port}")
|
|
private String serverPort;
|
|
|
|
@Value("${spring.profiles.active:local}")
|
|
private String profile;
|
|
|
|
@Value("${swagger.dev-url:https://kamco.dev-api.gs.dabeeo.com}")
|
|
private String devUrl;
|
|
|
|
@Value("${swagger.prod-url:https://api.kamco.com}")
|
|
private String prodUrl;
|
|
|
|
@Bean
|
|
public OpenAPI kamcoOpenAPI() {
|
|
// 1) SecurityScheme 정의 (Bearer JWT)
|
|
SecurityScheme bearerAuth =
|
|
new SecurityScheme()
|
|
.type(SecurityScheme.Type.HTTP)
|
|
.scheme("bearer")
|
|
.bearerFormat("JWT")
|
|
.in(SecurityScheme.In.HEADER)
|
|
.name("Authorization");
|
|
|
|
// 2) SecurityRequirement (기본으로 BearerAuth 사용)
|
|
SecurityRequirement securityRequirement = new SecurityRequirement().addList("BearerAuth");
|
|
|
|
// 3) Components 에 SecurityScheme 등록
|
|
Components components = new Components().addSecuritySchemes("BearerAuth", bearerAuth);
|
|
|
|
// profile 별 server url 분기
|
|
List<Server> servers = new ArrayList<>();
|
|
if ("dev".equals(profile)) {
|
|
servers.add(new Server().url(devUrl).description("개발 서버"));
|
|
servers.add(new Server().url("http://localhost:" + serverPort).description("로컬 서버"));
|
|
// servers.add(new Server().url(prodUrl).description("운영 서버"));
|
|
} else if ("prod".equals(profile)) {
|
|
// servers.add(new Server().url(prodUrl).description("운영 서버"));
|
|
servers.add(new Server().url("http://localhost:" + serverPort).description("로컬 서버"));
|
|
servers.add(new Server().url(devUrl).description("개발 서버"));
|
|
} else {
|
|
servers.add(new Server().url("http://localhost:" + serverPort).description("로컬 서버"));
|
|
servers.add(new Server().url(devUrl).description("개발 서버"));
|
|
// servers.add(new Server().url(prodUrl).description("운영 서버"));
|
|
}
|
|
|
|
return new OpenAPI()
|
|
.info(
|
|
new Info()
|
|
.title("KAMCO Change Detection API")
|
|
.description(
|
|
"KAMCO 변화 탐지 시스템 API 문서\n\n"
|
|
+ "이 API는 지리공간 데이터를 활용한 변화 탐지 시스템을 제공합니다.\n"
|
|
+ "GeoJSON 형식의 공간 데이터를 처리하며, PostgreSQL/PostGIS 기반으로 동작합니다.")
|
|
.version("v1.0.0"))
|
|
.servers(servers)
|
|
// 만들어둔 components를 넣어야 함
|
|
.components(components)
|
|
.addSecurityItem(securityRequirement);
|
|
}
|
|
}
|