【发布时间】:2021-07-29 20:11:32
【问题描述】:
我想在 Kotlin 上使用 Spring WebFlux 功能路由器创建 OpenAPI UI 规范。 Spring Boot v.2.5.2,springdoc-openapi v.1.5.9。 这是我的路由器类:
@Configuration
class UserServiceRouter {
@Bean
@RouterOperations(
RouterOperation(
path = "/user/{id}",
method = [RequestMethod.GET],
beanClass = UserService::class,
beanMethod = "getUserCredentialsById",
operation = Operation(
parameters = [Parameter(
style = ParameterStyle.SIMPLE,
explode = Explode.FALSE,
`in` = ParameterIn.PATH
)]
)
),
RouterOperation(
path = "/user/profile/{id}",
method = [RequestMethod.GET],
beanClass = UserService::class,
beanMethod = "getUserProfileById",
operation = Operation(
parameters = [Parameter(
style = ParameterStyle.SIMPLE,
explode = Explode.FALSE,
`in` = ParameterIn.PATH
)]
)
)
fun userRoute(userServiceHandler: UserServiceHandler) = coRouter {
("/user").nest {
GET("/{id}", userServiceHandler::getUserCredentialsById)
GET("/profile/{id}", userServiceHandler::getUserById)
}
}
}
我想创建一个类似的 GET 查询
http://localhost:8080/user/1
其中 1 是我想要的用户 ID。
但我的 OpenAPI 的 UI 仍然尝试使用 GET 参数创建查询
http://localhost:8080/user/{id}?id=1
这显然会导致错误 400。 很高兴知道应该如何正确配置我的@RouterOperations。
【问题讨论】:
标签: spring-webflux swagger-ui openapi springdoc springdoc-openapi-ui