<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.build()
.pathMapping("/")
.apiInfo(metaData());
}
private ApiInfo metaData() {
Contact contact = new Contact("성원준", "https://velog.io/@donsco", "cadqe13@gmail.com");
return new ApiInfo("",
"Spring Framework CAD",
"1.0",
"Terms of Service: ...",
contact,
"Apache License Version 2.0",
"https://www.apache.org/licenses/LICENSE-2.0",
new ArrayList<>());
}
}
@Api(description = "고객 컨트롤러")
@RestController
@RequestMapping(CustomerController.BASE_URL)
public class CustomerController {
public static final String BASE_URL = "/api/v1/customers";
private final CustomerService customerService;
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
@ApiOperation(value = "간략 설명", notes = "상세 설명")
@GetMapping
@ResponseStatus(HttpStatus.OK)
public CustomerListDTO getListOfCustomers(){
return new CustomerListDTO(customerService.getAllCustomers());
}
...
컨트롤러 상단에 @Api 어노테이션과 description을 추가해서 설명을 추가한다.
메서드에는 @ApiOperation 어노테이션으로 상세 설명을 적을 수 있다.
description은 현재 Deprecated 되어 있으니 tags 방식을 추천한다.
Swagger @Api Description is Deprecated
Api annotation's description is deprecated
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CustomerDTO {
@ApiModelProperty(value = "first name은 ~~입니다.", required = true)
private String firstname;
@ApiModelProperty(required = true )
private String lastname;
@JsonProperty("customer_url")
private String customerUrl;
}