-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from 7JEON8KI/fix/swagger--ISSUE-93
fix: 스웨거 헤더 붙이기
- Loading branch information
Showing
1 changed file
with
20 additions
and
14 deletions.
There are no files selected for viewing
34 changes: 20 additions & 14 deletions
34
src/main/java/com/hyundai/global/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
package com.hyundai.global.config; | ||
|
||
import org.springframework.stereotype.Component; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.ParameterBuilder; | ||
import springfox.documentation.schema.ModelRef; | ||
import springfox.documentation.service.Parameter; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
/** | ||
* author : 변형준 | ||
* fileName : SwaggerConfig | ||
* since : 2/16/24 | ||
*/ | ||
import java.util.Arrays; | ||
|
||
@Component | ||
@Configuration | ||
@EnableSwagger2 | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public Docket api() { | ||
// Authorization 헤더 추가 | ||
Parameter authHeader = new ParameterBuilder() | ||
.name("Authorization") // 헤더 이름 | ||
.description("Authorization") // 설명 | ||
.modelRef(new ModelRef("string")) // 타입 | ||
.parameterType("header") // 파라미터 타입 (헤더) | ||
.required(false) // 필수 여부 | ||
.build(); | ||
|
||
return new Docket(DocumentationType.SWAGGER_2) | ||
.globalOperationParameters(Arrays.asList(authHeader)) // 전역 파라미터 설정 | ||
.select() | ||
.apis(RequestHandlerSelectors.any()) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.pathMapping(""); | ||
// 여기에 API 선택 조건 추가 | ||
.build(); | ||
} | ||
} |