Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/02   »
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
Tags
more
Archives
Today
Total
관리 메뉴

거인의 코딩일지

[Spring boot] Swagger API 연동하기 본문

코딩/JAVA

[Spring boot] Swagger API 연동하기

코딩거인 2023. 10. 6. 10:28
728x90
Swagger 설정하는 방법

  • Swagger 설정하기 위한 라이브러리는 2가지가 있다
  • Spring - Fox , Spring - Dox 2가지 중에 사용하면 된다.
Spring - Fox
Spring - Doc

Gradle 설정하기
// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.7.0'
  • 제일 최근 버전이다. 위에 적어둔 홈페이지로 이동하여 원하는 버전으로 가져오면 된다.
Config 파일 만들기
@Configuration
public class DocsConfiguration {

    @Bean
    GroupedOpenApi testRegApi() {
        return GroupedOpenApi.builder()
                .pathsToMatch("/api/**")
                .displayName("definition")
                .group("Test")
                .build();
    }
}
Controller 설정
@RestController
@RequestMapping("api/test")
public class TestRegController {
    @Operation(summary = "get posts", description = "지역에 대한 posts들 가져오기")
    @ApiResponses({
            @ApiResponse(responseCode = "200", description = "OK"),
            @ApiResponse(responseCode = "400", description = "BAD REQUEST"),
            @ApiResponse(responseCode = "404", description = "NOT FOUND"),
            @ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR")
    })

 

 

참고문헌

 

[Spring boot] Swagger API 연동하기

Sprintdocs를 이용해 연동하기

velog.io

 

728x90