티스토리 뷰

Swagger(스웨거)는 API에 대한 메뉴얼 자동 생성 및 테스트 기능을 제공합니다. 




먼저 스웨거2 구현을 위한 Springfox사용을 위해 pom.xml에 dependency를 추가 합니다.

스웨거 UI는 스웨거가 생성하는 API문서를 사용자 대화 방식으로 만들어 주는 내장 솔루션입니다.


<!--Swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.2.2</version>
</dependency>
<!--Swagger UI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.2.2</version>
</dependency>


스웨거2는 @EnableSwagger2 어노테이션 설정으로 사용 가능합니다. 

@Configuration
@EnableSwagger2 // 스웨거 설정 가능케함
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET,
newArrayList(new ResponseMessageBuilder()
.code(500)
.message("500 message")
.responseModel(new ModelRef("Error"))
.build(),
new ResponseMessageBuilder()
.code(403)
.message("Forbidden!")
.build()));
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo(
"API Title ",
"API description.",
"API 1.0",
"Terms of service",
"annajinee@gmail.com",
"License of API",
"API license URL");
return apiInfo;
}
}



전체 소스는 아래의 깃에서 확인 가능합니다. 

https://github.com/annajinee/springboot-swagger-api


참고 사이트 :  http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api

       http://springboot.tistory.com/26


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함