0
votes

I'm using springdoc-openapi with Kotlin and WebFlux.fn.
I wanted to use @RouterOperation annotation at every path in CoRouterFunctionDsl but I couldn't.

@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)
        }
    }
}

There doesn't seem to be any relevant documentation about this.
How can I use @RouterOperation in coRouter DSL?

1

1 Answers

2
votes

The same principles applies to Kotlin DSL (coRouter): CoRouterFunctionDsl Beans are instances of RouterFunction.

Here is a sample syntax:

@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)
}