diff --git a/build.gradle b/build.gradle index 4fc85d6..4919187 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,9 @@ dependencies { annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" annotationProcessor "jakarta.annotation:jakarta.annotation-api" annotationProcessor "jakarta.persistence:jakarta.persistence-api" + + // Swagger + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' } tasks.named('test') { diff --git a/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java b/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java new file mode 100644 index 0000000..e746c7d --- /dev/null +++ b/src/main/java/com/dnd/accompany/global/config/docs/OpenApiConfig.java @@ -0,0 +1,41 @@ +package com.dnd.accompany.global.config.docs; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +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; + +@Configuration +@Profile({"local", "dev", "prod"}) +public class OpenApiConfig { + + @Bean + public OpenAPI openApi() { + Info info = new Info() + .title("DND API Document"); + + String jwtSchemeName = "Authorization"; + + SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName); + + Components components = new Components() + .addSecuritySchemes(jwtSchemeName, new SecurityScheme() + .name(jwtSchemeName) + .type(SecurityScheme.Type.HTTP) + .scheme("Bearer") + .bearerFormat("JWT")); + + return new OpenAPI() + .addServersItem(new Server().url("/")) + .components(new Components()) + .addSecurityItem(securityRequirement) + .components(components) + .info(info); + } +}