From 34cb7a10c3221af333717fd35b9d83f1b5e03e61 Mon Sep 17 00:00:00 2001 From: gitjiho Date: Fri, 15 Nov 2024 02:19:08 +0900 Subject: [PATCH] faet: set swagger route --- .../gdg/kkia/common/config/SwaggerConfig.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java b/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java index 71d0fed..79ec400 100644 --- a/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java +++ b/src/main/java/com/gdg/kkia/common/config/SwaggerConfig.java @@ -5,14 +5,29 @@ 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 org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; @Configuration public class SwaggerConfig { + private static final String LOCAL_SERVER_URL = "http://localhost:8080"; + private static final String PROD_SERVER_URL = "http://kkia.backapi.site:8100"; + private final Environment environment; + + public SwaggerConfig(Environment environment) { + this.environment = environment; + } @Bean public OpenAPI openAPI() { + String serverUrl = LOCAL_SERVER_URL; + + if (environment.acceptsProfiles(Profiles.of("prod"))) { + serverUrl = PROD_SERVER_URL; + } return new OpenAPI() .components(new Components() @@ -22,6 +37,7 @@ public OpenAPI openAPI() { .scheme("bearer") .bearerFormat("JWT"))) .info(apiInfo()) + .addServersItem(new Server().url(serverUrl)) .addSecurityItem(new SecurityRequirement().addList("bearerAuth")); } @@ -29,6 +45,6 @@ private Info apiInfo() { return new Info() .title("77ㅑ 팀 API 명세서") .description("화이팅!") - .version("0.0.1"); + .version("0.0.2"); } }