Skip to content

Commit

Permalink
Merge pull request #37 from 7JEON8KI/fix/swagger--ISSUE-93
Browse files Browse the repository at this point in the history
fix: 스웨거 헤더 붙이기
  • Loading branch information
kangeunku authored Mar 2, 2024
2 parents ce612e5 + 212d860 commit 62a2f52
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/com/hyundai/global/config/SwaggerConfig.java
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();
}
}

0 comments on commit 62a2f52

Please sign in to comment.