글의 내용은 대부분 아래 블로그를 참조함
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private String version;
private String title;
@Bean
public Docket apiV1() {
version = "V1";
title = "API VERSION : " + version;
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.groupName(version)
.select()
.apis(RequestHandlerSelectors.basePackage("swagger.practice.tentwelve"))
.paths(PathSelectors.ant("/v1/api/**"))
.build()
.apiInfo(apiInfo(title, version));
}
}
@Configuration, @EnableSwagger2 -> 기능 선언
@Bean 핵심이 되는 bean 설정
Docket -> Swagger 핵심이 되는 bean
useDefaultResponseMessages(false)
200,400 번등 status code를 자동으로 만들어주는 기능. 오류가 날 수 있기에 꺼준다.
groupName : 위에서 선언한 version
select() : ApiSelectorBuilder를 생성
api : package 위치를 지정, controller로 지정하면 되는 듯
paths : 연결되는 path
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.ec.sticket.controllers") )
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, getArrayList());
}
@RestController
@Api(value = "BoardController V1")
@RequestMapping("/v1/api")
public class BoardControllerV1 {
@ApiOperation(value = "아티스트 가져오기", notes = "모든 아티스트 가져온다 이놈아.")
@ApiResponses({
@ApiResponse(code = 200, message = "OK !!"),
@ApiResponse(code = 500, message = "Internal Server Error !!"),
@ApiResponse(code = 404, message = "Not Found !!")
})
@GetMapping("/board")
public Map<String, String> selectOneBoard(@ApiParam(value = "게시판번호", required = true, example = "1") @RequestParam(defaultValue = "얼수",required = true) String name) {
Map<String, String> result = new HashMap<>();
result.put("임얼쑤",name);
return result;
}
}
@EnableSwagger2
public class SwaggerConfig {
private String version;
private String title;
@Bean
public Docket apiV1() {
version = "V1";
title = "API VERSION : " + version;
List<ResponseMessage> responseMessages = new ArrayList<>();
responseMessages.add(new ResponseMessageBuilder()
.code(200)
.message("OK ~~")
.build());
responseMessages.add(new ResponseMessageBuilder()
.code(404)
.message("Not Found ~~")
.build());
responseMessages.add(new ResponseMessageBuilder()
.code(500)
.message("Internal Server Error ~~")
.build());
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.groupName(version)
.select()
.apis(RequestHandlerSelectors.basePackage("swager.practice.tentwelve"))
.paths(PathSelectors.ant("/v1/api/**"))
.build()
.apiInfo(apiInfo(title, version))
.globalResponseMessage(RequestMethod.GET, responseMessages);
}
}
@Api(tag = " " )
https://stackoverflow.com/questions/37961620/springfox-restcontroller-naming
https://stackoverflow.com/questions/38074936/api-annotations-description-is-deprecated