Skip to content

Commit

Permalink
refactor: 하드코딩 제거 & 역할 별 메서드 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjy committed Mar 20, 2024
1 parent bbe23f2 commit 853bc0d
Showing 1 changed file with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,47 @@
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 java.util.List;

@Configuration
public class SwaggerConfig {
private final String JWT = "JWT";
private final String BEARER = "Bearer";

@Bean
public OpenAPI openAPI() {
String jwt = "JWT";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwt);
Components components = new Components().addSecuritySchemes(jwt, new SecurityScheme()
.name(jwt)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
);
SecurityRequirement securityRequirement = new SecurityRequirement().addList(JWT);
return new OpenAPI()
.components(new Components())
.info(apiInfo())
.servers(getServers())
.info(getInfo())
.addSecurityItem(securityRequirement)
.components(components);
.components(getComponents());
}

private Info apiInfo() {
private List<Server> getServers() {
return List.of(new Server()
.url("/api")
.description("백엔드 api 서버")
);
}

private Info getInfo() {
return new Info()
.title("API Test")
.description("Let's practice Swagger UI")
.title("Roll The Dice API")
.description("요약된 뉴스를 AR로 재미있게 즐기는 서비스")
.version("demo");
}

private Components getComponents() {
return new Components().addSecuritySchemes(JWT, new SecurityScheme()
.name(JWT)
.type(SecurityScheme.Type.HTTP)
.scheme(BEARER)
.bearerFormat(JWT)
);
}
}

0 comments on commit 853bc0d

Please sign in to comment.