Skip to content

Commit

Permalink
✨ Feat: Swagger 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
strongmhk committed Jul 4, 2024
1 parent 8979af2 commit cff8460
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/umc/dream/TestController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;

@RestController
public class TestController {

@GetMapping("/health")
@Operation(summary = "health check API",description = "인스턴스의 health check하는 API입니다")
public String healthCheck() {
return "I'm healthy!";
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/umc/dream/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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/**

0 comments on commit cff8460

Please sign in to comment.