20240312 전자정부(스웨거) / 못써서 삭제했음

2024. 3. 12. 14:352023.11.21-2024.05.31

build.gradle> swagger 추가

	implementation 'io.springfox:springfox-swagger2:2.9.2'
	implementation 'io.springfox:springfox-swagger-ui:2.9.2'

 

 

SwaggerConfig > 클래스 생성

package com.mask.web.util;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.net.HttpHeaders;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	
	private static final String API_NAME="";
	private static final String API_VERSION="";
	private static final String API_DESCRIPTION = "스프링 부트 API 명세서";

	@Bean
	public Docket api() {
		Parameter parameter = new ParameterBuilder(). //API에 전역 파라미터를 설정
				name(HttpHeaders.AUTHORIZATION).
				description("token").
				modelRef(new ModelRef("model")).
				parameterType("").
				required(false).
				build();
		
		List<Parameter> paramList = new ArrayList<>();
		paramList.add(parameter);
				
		return new Docket(DocumentationType.SWAGGER_2).
				globalOperationParameters(paramList).
				apiInfo(apiInfo()). //api이름을 아래 메소드에서 설정합니다.  =정보
				select().
				apis(RequestHandlerSelectors.basePackage("com.mask.web")).//스웨거를 적용할 클래스 패키지
				paths(PathSelectors.any()).//위 패키지 하위에 모든 패키지를 적용합니다. 
				build();

	}//end api
	
	public ApiInfo apiInfo() {
		return new ApiInfoBuilder().
				title(API_NAME).
				version(API_VERSION).
				description(API_DESCRIPTION).
				build();
	}
}