Java 17
SpringBoot 3.2.3
IntelliJ
Mac OS (M3)
Swagger는 API를 설명하고 문서화하며, 개발 및 테스트를 용이하게 하는 오픈 소스 프레임워크입니다. Swagger는 RESTful API를 문서화하고 사용할 수 있는 툴이며, API의 명세를 정의하고 해당 명세를 기반으로 자동으로 API 문서를 생성할 수 있습니다.
더 자세한 내용은 다음 링크를 방문해 확인하기 바랍니다.
swagger 공식문서
// swagger 적용
implementation "org.springdoc:springdoc-openapi-starter-common:${springDocVersion}"
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springDocVersion}"
swagger-ui:
path: /
disable-swagger-default-url: true
display-request-duration: true
operations-sorter: alpha
doc-expansion: none
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.components(new Components())
.info(apiInfo());
}
private Info apiInfo() {
return new Info()
.title("API service")
.description("API를 제공하는 서비스입니다.")
.version("1.0.0");
}
}
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("v1/route")
@RequiredArgsConstructor
@Tag(name = "길찾기 관련 API", description = "안전길찾기에 대한 라우팅 시스템의 API를 제공합니다.")
public class RouteController {
private final RouteService routeService;
@PostMapping
@Operation(summary = "안전 길찾기", description = "사용자가 입력한 출발지와 도착지에 맞는 안전 길찾기를 합니다.")
public RouteCreateResponse createResponse(
@RequestBody RouteCreateRequest request
){
return routeService.createRoute(request);
}
}
http://localhost:8080/swagger-ui/index.html
스프링부트 실행 후, 해당 주소로 방문하여 등록된 API를 확인합니다.
이러면 성공 !