๐ ๏ธ ๊ฐ๋ฐ ํ๊ฒฝ
๐ Spring : Spring Boot 3.1.3
๐ ๏ธ Java : Amazon corretto 17
๐ ์์กด์ฑ
Spring Boot 3.x ๋ฒ์ ๋ถํฐ springfox
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ง์ํ์ง ์๊ธฐ ๋๋ฌธ์ springdoc-openapi
๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
๐ ๏ธ ์ ์ฉ
springfox
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ฌ๋ฌ ์ค์ ์ ํด์ค์ผํ์ง๋ง, springdoc-openapi
์ ์ค์ ์กฐ์ฐจ ํ์์์ด ๋ฐ๋ก ์ฌ์ฉํ ์ ์๋ค.
public class TestController {
@Operation(
summary = "ํ
์คํธ ์์ฒญ",
description = "ํ
์คํธ ์์ฒญ์ ๋ํ API"
)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "ํ
์คํธ ์ฑ๊ณต"),
@ApiResponse(responseCode = "204", description = "์กฐํ ๋ฐ์ดํฐ ์์"),
@ApiResponse(responseCode = "400", description = "์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ ์ค๋ฅ")
})
@GetMapping("")
public ResponseData.ApiResult<Area> testApi() {
...
return ResponseData.success(area);
}
}
์์ ๊ฐ์ด @Operation
๋ฅผ ์ด์ฉํด API์ ๋ํ ์ค๋ช
์ ์์ฑํ ์ ์๊ณ , @ApiResponse
๋ฅผ ํตํด ๋ฐํ ๋ฐ์ดํฐ๋ ์ฝ๋๋ฅผ ์ ์ํ ์ ์๋ค.
๐งฉ ํ ์คํธ
์๋ฒ๋ฅผ ์คํํ๊ณ , ์๋ URL์ ํตํด ์ ์ํ๋ฉด API ๋ช ์ธ๋ฅผ ์์ธํ๊ฒ ๋ณผ ์ ์๋ค.
http://localhost:8080/swagger-ui/index.html
Reference
'Spring > ๊ธฐ๋ฅ ์ ๋ฆฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JUnit5] - @Nested ํ ์คํธ ์์ ์ง์ (2) | 2023.10.08 |
---|---|
[Spring] - Jsoup์ ์ด์ฉํ ํฌ๋กค๋ง (1) | 2023.09.12 |
[Spring] - Naver Api๋ก ์ํ ๊ฒ์ ๋ชฉ๋ก ๋ฐ์์ค๊ธฐ (0) | 2023.09.10 |
[Spring] - record DTO (0) | 2023.09.10 |
[Spring] - Spring Scheduler (0) | 2023.09.10 |