- Swagger๋ ๊ฐ๋ฐํ REST API๋ฅผ ํธ๋ฆฌํ๊ฒ ๋ฌธ์ํํด์ฃผ๊ณ , ์ด๋ฅผ ํตํด์ ํธ๋ฆฌํ๊ฒ API๋ฅผ ํธ์ถํ๊ณ ํ
์คํธํ ์ ์๋ ํ๋ก์ ํธ์ด๋ค
- Swagger์ ๋ํ ์ข
ํฉ์ ์ธ ๊ตฌ์ฑ์ ๊ฐํธํ๊ฒ ์ถ๊ฐํ๊ณ , configuration ํ์ผ ์์ด๋ ๊ฐ๊ฒฐํ๊ฒ ํ๋ก์ ํธ๋ฅผ ๊ด๋ฆฌํ๊ณ ์ถ๋ค๋ฉด
SpringFox Boot Starter
์ ๋ํ ์์กด์ฑ์ ์ถ๊ฐํ๋ฉด ๋๋ค
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.OAS_30)
.useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.basePackage("com.velog.eunjy.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Swagger Test")
.description("SwaggerConfig")
.version("3.0")
.build();
}
}
- configuration ํ์ผ์ธ
SwaggerConfig.java
ํ์ผ์ด๋ค
-
Docket
: Swagger ์ค์ ์ ํต์ฌ์ด ๋๋ Bean
-
useDefaultResponseMessages
: Swagger์์ ์ ๊ณตํด์ฃผ๋ ๊ธฐ๋ณธ ์๋ต ์ฝ๋ (200, 401, 403, 404)
-
false
: ๊ธฐ๋ณธ ์๋ต ์ฝ๋๋ฅผ ๋
ธ์ถํ์ง ์์
-
apis
: api ์คํ์ด ์์ฑ๋์ด ์๋ ํจํค์ง(Controller)๋ฅผ ์ง์
-
paths
: apis์ ์๋ API ์ค ํน์ path๋ฅผ ์ ํํ๋ค
-
apiInfo
: Swagger UI๋ก ๋
ธ์ถํ ์ ๋ณด
