0

我将 springdoc-openapi 与 Kotlin 和 WebFlux.fn 一起使用。
我想在 CoRouterFunctionDsl 的每个路径上使用 @RouterOperation 注释,但我做不到。

@Configuration
class UserRouter(private val userHandler: UserHandler) {
    // @RouterOperations annotation works here.
    @Bean
    fun userRouter = coRouter {
        ("/v1").nest {
            // I want to use @RouterOperation annotation here.
            GET("/users", userHandler::getUsers)

            // I want to use @RouterOperation annotation here.
            GET("/users/{userId}", userHandler::getUserById)

            // I want to use @RouterOperation annotation here.
            POST("/users", userHandler::postUser)
        }
    }
}

似乎没有任何相关文档。
如何在 coRouter DSL 中使用 @RouterOperation?

4

1 回答 1

2

同样的原则也适用于 Kotlin DSL(coRouter): CoRouterFunctionDsl Bean 是 RouterFunction 的实例。

这是一个示例语法:

@FlowPreview
@Bean
@RouterOperations(
        RouterOperation(path = "/test", method = arrayOf(RequestMethod.GET), beanClass = ProductRepositoryCoroutines::class, beanMethod = "getAllProducts"),
        RouterOperation(path = "/test/{id}", method = arrayOf(RequestMethod.GET), beanClass = ProductRepositoryCoroutines::class, beanMethod = "getProductById"))
fun productRoutes(productsHandler: ProductsHandler) = coRouter {
    GET("/test", productsHandler::findAll)
    GET("/test/{id}", productsHandler::findOne)
}
于 2020-07-03T08:54:41.217 回答