Skip to content

Commit

Permalink
Merge pull request #25 from team1-healthy-fb-hackerton/feat/issue-20-…
Browse files Browse the repository at this point in the history
…itemRegister

jwt swagger
  • Loading branch information
2hy2on authored May 3, 2024
2 parents 23f23c9 + 9b35a52 commit 3ab75fb
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/main/java/team1/hackerton/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
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 io.swagger.v3.oas.models.servers.Server;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -14,12 +19,27 @@
public class SwaggerConfig {

@Bean
public GroupedOpenApi team1() {
String[] paths = {"/"};
public OpenAPI API() {
io.swagger.v3.oas.models.info.Info info = new io.swagger.v3.oas.models.info.Info()
.title("API")
.description("API 명세서")
.version("1.0.0");

return GroupedOpenApi.builder()
.group("team1")
.pathsToMatch(paths)
.build();
String jwtSchemeName = "JWT TOKEN";
// API 요청헤더에 인증정보 포함
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName);
// SecuritySchemes 등록
Components components = new Components()
.addSecuritySchemes(jwtSchemeName, new SecurityScheme()
.name(jwtSchemeName)
.type(SecurityScheme.Type.HTTP) // HTTP 방식
.scheme("bearer")
.bearerFormat("JWT"));

return new OpenAPI()
.addServersItem(new Server().url("/"))
.info(info)
.addSecurityItem(securityRequirement)
.components(components);
}
}

0 comments on commit 3ab75fb

Please sign in to comment.