Gradle에서 진행했습니다.
application.properties 에 다음과 같은 항목을 추가합니다.
# Swagger
springfox.documentation.swagger.use-model-v3=false
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER
//swager
// <https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui>
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
// <https://mvnrepository.com/artifact/io.springfox/springfox-swagger2>
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
/**
* API 문서 관련 swagger2 설정 정의.
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.enable(true)
.securityContexts(newArrayList(securityContext()))
.securitySchemes(newArrayList(apiKey()))
;
}
private ApiInfo apiInfo() {
return new ApiInfo(
"Motoo REST API",
"ㅇㅇ API 입니다.",
"V1",
"호스트 주소",
new Contact("", "", ""),
"", "", Collections.emptyList());
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
// -- Static resources
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css");
registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
registry.addResourceHandler("/images/**").addResourceLocations("classpath:/static/images/");
}
//
//
private ApiKey apiKey() {
return new ApiKey(SECURITY_SCHEMA_NAME, "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.build();
}
public static final String SECURITY_SCHEMA_NAME = "JWT";
public static final String AUTHORIZATION_SCOPE_GLOBAL = "global";
public static final String AUTHORIZATION_SCOPE_GLOBAL_DESC = "accessEverything";
private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope(AUTHORIZATION_SCOPE_GLOBAL, AUTHORIZATION_SCOPE_GLOBAL_DESC);
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return newArrayList(new SecurityReference(SECURITY_SCHEMA_NAME, authorizationScopes));
}
@Bean
UiConfiguration uiConfig() {
return UiConfigurationBuilder.builder()
// .supportedSubmitMethods(newArrayList("get").toArray(new String[0])) // try it 기능 활성화 범위
// .operationsSorter(METHOD)
.build();
}
}