본문 바로가기

프로젝트

[ 프로젝트 ] Swagger 적용

Swagger 적용 이유

인생퍼즐 프런트, 백엔드의 리팩터링을 진행을 하고 있다. 같이 진행하다보니 API 명세가 안되어 있어 프런트, 백엔드가 어긋나는 부분이 생겼다. 그로 인해 시간을 더 써야하는 문제가 발생했다. 이 문제를 해결과 추후 기능 개발 및 유지보수를 위해 Swagger를 적용해 API 명세를 하기로 했다.

Swagger 라이브러리 선택

자바 스프링에서 Swagger 라이브러리로 SpringFox를 많이 사용이 된다. 하지만 Swagger의 버전은 올라가지만 SpringFox 라이브러리는 2020.10을 마지막으로 업데이트가 이루어지지 않는다는 문제가 있었다. 최근까지 계속 업데이트가 이루어지고 있는 SpringDoc에서 제공하는 라이브러리를 사용하기로 했다.

 

OpenAPI 3 Library for spring-boot

Library for OpenAPI 3 with spring boot projects. Is based on swagger-ui, to display the OpenAPI description.Generates automatically the OpenAPI file.

springdoc.org

자바 스프링 Swagger 설정

1. build.gradle

 

implementation 'org.springdoc:springdoc-openapi-ui:1.6.12'

 

2. application.yml

 

springdoc:
  packages-to-scan: package.name
  default-consumes-media-type: application/json;charset=UTF-8
  default-produces-media-type: application/json;charset=UTF-8
  swagger-ui:
    path: swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha
  cache:
    disabled: true