API 문서화는 백엔드 개발자 외 분들이 보기위함으로 만들곤 했다.
implementation("org.springframework.boot:spring-boot-devtools")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")
import io.swagger.v3.oas.annotations.OpenAPIDefinition
import io.swagger.v3.oas.annotations.info.Info
import org.springdoc.core.models.GroupedOpenApi
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@OpenAPIDefinition(
info = Info(title = "API 명세",
description = "API 명세",
version = "v1")
)
@Configuration
class SwaggerConfig {
@Bean
fun api(): GroupedOpenApi {
val paths = arrayOf("/api/**")
return GroupedOpenApi.builder()
.group("API")
.pathsToMatch(*paths)
.build()
}
}
@ApiResponses(value = [
ApiResponse(responseCode = "400", description = "Bad Request", content = [Content(schema = Schema(implementation = HttpException::class))]),
ApiResponse(responseCode = "401", description = "Unauthorized"),
ApiResponse(responseCode = "403", description = "Forbidden"),
ApiResponse(responseCode = "404", description = "Not Found"),
ApiResponse(responseCode = "500", description = "Internal Server Error")
])
@PostMapping("")
fun testRequestApi(@RequestBody body: BodyRequestDto): ResponseEntity<CoreSuccess> {
return ResponseEntity.ok(userService.testRequestApi(body))
}