์ž๋™์ƒ์„ฑ๋œ ์Šค์›จ๊ฑฐ API ๋ฌธ์„œ

์Šค์›จ๊ฑฐ๋Š” ๋ฐฑ์—”๋“œ์—์„œ ๊ฐœ๋ฐœํ•œ API๋ฅผ ๋ฌธ์„œํ™”ํ•ด์ฃผ๋Š” ํˆด๋กœ ๊ฐœ๋ฐœ ์ง„ํ–‰์ค‘์ผ ๋•Œ ๋ฟ๋งŒ์•„๋‹ˆ๋ผ ์šด์˜์ค‘์—๋„ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๊ธฐ๋„ ํ•˜๋Š”๋ฐ์š”

์Šค์›จ๊ฑฐ ๋ฒ„์ „์ด 3์œผ๋กœ ์˜ฌ๋ผ๊ฐ€๋ฉด์„œ ์„ค์ • ๋ฐ ๊ธฐ๋ณธ url์ด ๋ณ€๊ฒฝ์ด ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์Šค์›จ๊ฑฐ ๋ฒ„์ „ ์—…์— ๋‘์–ด๋ฒˆ ์‹คํŒจํ•œ ๋์— ๊ฐ€์žฅ ๊ฐ„๋‹จํžˆ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ๊ตฌํ•ด์™”์Šต๋‹ˆ๋‹ค.

 

์Šคํ”„๋ง๋ถ€ํŠธ ์Šค์›จ๊ฑฐ ์„ค์ •

๋ฒ„์ „์€ ์Šคํ”„๋ง๋ถ€ํŠธ 2.4.0, ์Šค์›จ๊ฑฐ 3.0.0 ์ž…๋‹ˆ๋‹ค.

 

1. ์Šคํ”„๋ง ๋ถ€ํŠธ์™€ ์Šค์›จ๊ฑฐ ์˜์กด์„ฑ ์ถ”๊ฐ€

๋ฉ”์ด๋ธํ”„๋กœ์ ํŠธ

<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-boot-starter</artifactId>
	<version>3.0.0</version>
</dependency>
<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-swagger-ui</artifactId>
	<version>3.0.0</version>
</dependency>

 

๊ทธ๋ž˜๋“ค ํ”„๋กœ์ ํŠธ

repositories {
	jcenter()
}

dependencies {
	implementation "io.springfox:springfox-boot-starter:3.0.0"
	implementation "io.springfox:springfox-swagger-ui:3.0.0"
}

 

2. ์„ค์ •ํ•˜๊ธฐ

SwaggerConfig ํด๋ž˜์Šค๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ ์•„๋ž˜์™€ ๊ฐ™์ด @Configuration ์–ด๋…ธํ…Œ์ด์…˜์„ ๋ถ™์—ฌ์ฃผ๊ณ  Docket ๋นˆ์„ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ข€ ๋” ์ƒ์„ธํ•œ ์„ค์ •์„ ํ•˜๋ ค๋ฉด ๊ณต์‹์‚ฌ์ดํŠธ์—์„œ ํ™•์ธ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

@Configuration
public class SwaggerConfig {

	@Bean
	public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
		.select()
		.apis(RequestHandlerSelectors.any())
		.paths(PathSelectors.any())
		.build();
	}
}

 

3. ์ ‘์† URL

๊ธฐ์กด์˜ 2.x ๋ฒ„์ „๊นŒ์ง€๋Š” host<:port>/<context root>/swagger-ui.html ๋กœ ์ ‘์†์„ ํ–ˆ์—ˆ๋‹ค๋ฉด, v3๋ถ€ํ„ฐ๋Š” host<:port>/<context root>/swagger-ui/ ๋˜๋Š” host<:port>/<context root>/swagger-ui/index.html ๋กœ ์ ‘์†์„ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

 

์ฐธ๊ณ ๋ฌธ์„œ: https://springfox.github.io/springfox/docs/current/