1. build.gradle 추가
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
2. config 패키지에 SwaggerConfig 작성
@Configuration
@EnableSwagger2
public class SwaggerConfig {
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("USER-SERVICE")
.description("USER API")
.version("1.0")
.build();
}
@Bean
public Docket commonApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.ant("/user-service/**"))
.build();
}
}
3. 컨트롤러에 ApiOperation 어노테이션 추가
@ApiOperation(value="회원가입")
@PostMapping("/user")
public Long createUser(@RequestBody RequestUserDto dto){
return userService.createUser(dto);
}
@ApiOperation(value="회원정보 수정")
@PutMapping("/user")
public ResponseEntity<ResponseUserDto> modify(@RequestBody RequestUserDto dto){
return userService.modify(dto);
}
@ApiOperation(value="로그인" , notes = "[응답코드]\n로그인 성공 : 200\n로그인 실패 : 404\n 로그인 성공시 token 발급")
@PostMapping("/login")
public ResponseEntity<JWTDto> login(@RequestBody LoginDto loginDto){
return userService.login(loginDto.getEmail(),loginDto.getPassword());
}
4. 필드에 @ApiModelProperty로 예제 설명
@ApiModelProperty(example = "eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOj22MzA0NDAxMjcsImV4cCI6MTYzMjAzMjEyNywic3ViIjoidGVzdDFAbmF2ZXIuY29tIn0.R-BAIAPMpSdcspxXrnnck6AM8LvNBeIxC5Y4TyG_rKc")
private String token;