์์ํ๊ธฐ ์
Spring Boot ํ๋ก์ ํธ์์ API ๋ฌธ์๋ฅผ ์๋์ผ๋ก ๋ง๋ค์ด์ฃผ๋ Swagger UI๋ ๊ฐ๋ฐ ํ์
๊ณผ ํ
์คํธ์ ํฐ ๋์์ด ๋ฉ๋๋ค.
์ ๋ Maven ํ๊ฒฝ์์ springdoc-openapi๋ฅผ ์ ์ฉํ ๊ณผ์ ์ ์ ๋ฆฌํด๋ณด์์ต๋๋ค.
1. pom.xml ์ค์
<dependencies> ... </dependencies> ์์ Swagger ์์กด์ฑ์ ์ถ๊ฐํฉ๋๋ค.
<dependencies>
...
</dependencies> ์๋์
<!-- # ์ค์ ์ ์ฅ์(repository) ๋ช
์์ ์ผ๋ก ์ถ๊ฐ -->
<repositories>
<repository>
<id>central</id>
<name>Maven Central Repository</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
</repositories>
๋ง์ฝ dependency not found ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค๋ฉด,
์ค์ ์ ์ฅ์(repository)๋ฅผ ๋ชป ์ฐพ๋ ๊ฒฝ์ฐ์ด๋ฏ๋ก ์ repositories ์ฝ๋๋ฅผ ์ถ๊ฐํ ๋ค Maven Reload๋ฅผ ํด์ฃผ๋ฉด ์ ์์ ์ผ๋ก ๋์ํฉ๋๋ค.
<!-- # Swagger (springdoc-openapi-ui) -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
2. application.properties ์ถ๊ฐ
# Swagger UI
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
๊ธฐ๋ณธ path๋ ์ํ๋ ๋๋ก ๋ฐ๊ฟ ์ ์์ต๋๋ค.
์ ๋ swagger-ui.html๋ก ์ง์ ํ๊ธฐ ๋๋ฌธ์, ์๋ ์ฃผ์๋ก ์ ์ํ๋ฉด Swagger UI ํ๋ฉด์ ํ์ธํ ์ ์์ต๋๋ค.
http://localhost:8080/swagger-ui/index.html
Swagger UI ํ์ฉํ๊ธฐ
์ ์์ ์ผ๋ก ์ ์ํ๋ฉด, API๊ฐ ์๋์ผ๋ก ๋ฌธ์ํ๋ ํ๋ฉด์ด ๋ํ๋ฉ๋๋ค.

API ์ค๋ช ์ Controller ์ฝ๋์ @Operation ์ด๋ ธํ ์ด์ ์ ํ์ฉํด์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
@Operation(summary = "์ ์ ์
๋ฐ์ดํธ", description = "์ ์ ์ ๋ณด๋ฅผ ์
๋ฐ์ดํธํฉ๋๋ค.")
@PostMapping("/update")
public ResponseEntity<UserDTO> updateUser(@RequestBody UserDTO dto) {
...
}
์ด๋ ๊ฒ ์์ฑํ๋ฉด Swagger UI์ **์ ๋ชฉ(summary) + ์ค๋ช (description)**์ด ํจ๊ป ํ์๋์ด, ํ์ ์์ ๋งค์ฐ ์ ์ฉํฉ๋๋ค.
Try it out ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ธ๋ผ์ฐ์ ์์ ์ง์ API ์์ฒญ์ ํ
์คํธํ ์ ์์ต๋๋ค.

Maven ํ๊ฒฝ์์๋ springdoc-openapi ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ง ์ถ๊ฐํ๋ฉด ์์ฝ๊ฒ Swagger UI๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค.
API ํ
์คํธ, ํ์
, ๋ฌธ์ํ๋ฅผ ํ ๋ฒ์ ํด๊ฒฐํ ์ ์์ผ๋ ๊ผญ ๋์
ํด๋ณด์๊ธธ ์ถ์ฒ๋๋ฆฝ๋๋ค.