diff --git a/build.gradle b/build.gradle index bbd8009..ad496dd 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,8 @@ repositories { dependencies { //implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' // swagger + compileOnly 'org.projectlombok:lombok' //runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/umc/dream/TestController.java b/src/main/java/com/umc/dream/TestController.java index b23066a..68a5d86 100644 --- a/src/main/java/com/umc/dream/TestController.java +++ b/src/main/java/com/umc/dream/TestController.java @@ -1,5 +1,6 @@ package com.umc.dream; +import io.swagger.v3.oas.annotations.Operation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -7,6 +8,7 @@ public class TestController { @GetMapping("/health") + @Operation(summary = "health check API",description = "인스턴스의 health check하는 API입니다") public String healthCheck() { return "I'm healthy!"; } diff --git a/src/main/java/com/umc/dream/config/SwaggerConfig.java b/src/main/java/com/umc/dream/config/SwaggerConfig.java new file mode 100644 index 0000000..bdb965c --- /dev/null +++ b/src/main/java/com/umc/dream/config/SwaggerConfig.java @@ -0,0 +1,35 @@ +package com.umc.dream.config; + +import io.swagger.v3.oas.annotations.servers.Server; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import java.util.Arrays; + +@Configuration +public class SwaggerConfig implements WebMvcConfigurer { + + private static final String BEARER_TOKEN_PREFIX = "Bearer"; + + @Bean + public OpenAPI openAPI() { + String jwtSchemeName = "JWT TOKEN"; + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme(BEARER_TOKEN_PREFIX) + .bearerFormat("JWT")); + + // Swagger UI 접속 후, 딱 한 번만 accessToken을 입력해주면 모든 API에 토큰 인증 작업이 적용됩니다. + return new OpenAPI() + .addSecurityItem(securityRequirement) + .components(components); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index a7fd2eb..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=dream diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..de6af51 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,23 @@ +spring: + application: + name: dream + + +springdoc: + swagger-ui: + # swagger-ui ?? ??. default ?? /swagger-ui.html??. + path: /swagger-custom-ui.html + + # openAPI ?? ??. default ?? /v3/api-docs ??. + api-docs: + path: /api-docs + + # request media type ? ?? ? + default-consumes-media-type: application/json + + # response media type ? ?? ? + default-produces-media-type: application/json + + # ?? ??? ???? controller? swagger-ui? ????. +# paths-to-match: +# - /api/** \ No newline at end of file