Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 스웨거 헤더 붙이기 #37

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading