New file |
| | |
| | | package kr.wisestone.owl.config; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import springfox.documentation.builders.ApiInfoBuilder; |
| | | import springfox.documentation.builders.PathSelectors; |
| | | import springfox.documentation.builders.RequestHandlerSelectors; |
| | | 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; |
| | | |
| | | /** |
| | | * API 문서 제작 패키지 Swagger 설정 클래스 |
| | | */ |
| | | @Configuration |
| | | @EnableSwagger2 |
| | | public class SwaggerConfig { |
| | | |
| | | private static final String API_NAME = "OWL API"; |
| | | private static final String API_VERSION = "1.0.0"; |
| | | private static final String API_DESCRIPTION = "OWL API 명세서"; |
| | | |
| | | |
| | | /** |
| | | * API 설정 |
| | | * @return docket class |
| | | */ |
| | | @Bean |
| | | public Docket api() { |
| | | // Parameter parameterBuilder = new ParameterBuilder() |
| | | // .name(HttpHeaders.AUTHORIZATION) |
| | | // .description("Access Tocken") |
| | | // .modelRef(new ModelRef("string")) |
| | | // .parameterType("header") |
| | | // .required(false) |
| | | // .build(); |
| | | |
| | | List<Parameter> globalParameters = new ArrayList<>(); |
| | | // globalParameters.add(parameterBuilder); |
| | | |
| | | return new Docket(DocumentationType.SWAGGER_2) |
| | | .globalOperationParameters(globalParameters) |
| | | .consumes(getConsumeContentTypes()) |
| | | .produces(getProduceContentTypes()) |
| | | .apiInfo(apiInfo()) |
| | | .select() |
| | | .apis(RequestHandlerSelectors.basePackage("kr.wisestone.owl.web.controller.Api")) |
| | | .paths(PathSelectors.any()) |
| | | .build(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * API 문서 타이틀/버전/설명 설정 |
| | | * @return ApiInfo 클래스 |
| | | */ |
| | | public ApiInfo apiInfo() { |
| | | return new ApiInfoBuilder() |
| | | .title(API_NAME) |
| | | .version(API_VERSION) |
| | | .description(API_DESCRIPTION) |
| | | .build(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * API 문서 테스트 Request Content-Type 설정 추가 |
| | | * @return consumes content-type 목록 |
| | | */ |
| | | private Set<String> getConsumeContentTypes() { |
| | | Set<String> consumes = new HashSet<>(); |
| | | consumes.add("application/json;charset=UTF-8"); |
| | | consumes.add("application/x-www-form-urlencoded"); |
| | | return consumes; |
| | | } |
| | | |
| | | /** |
| | | * API 문서 테스트 Response content-type 설정 추가 |
| | | * @return produce content-type 목록 |
| | | */ |
| | | private Set<String> getProduceContentTypes() { |
| | | Set<String> produces = new HashSet<>(); |
| | | produces.add("application/json;charset=UTF-8"); |
| | | return produces; |
| | | } |
| | | } |