Skip to content

Commit

Permalink
feat: Swagger UI 설정을 추가한다.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlarltj committed Jul 17, 2024
1 parent 69b9388 commit 55b7c4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 55b7c4d

Please sign in to comment.