From 48c660fa41ec954a566ea1891018aa83fece9667 Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Wed, 5 Sep 2018 16:53:59 +0200 Subject: [PATCH] Add support for empty router in RouterFunctionDsl Issue: SPR-17247 --- .../web/reactive/function/server/RouterFunctionDsl.kt | 7 ++++++- .../web/reactive/function/server/RouterFunctionDslTests.kt | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt index 1cee19ecefa..1672c434a89 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt @@ -546,7 +546,12 @@ open class RouterFunctionDsl(private val init: RouterFunctionDsl.() -> Unit) : ( */ override fun invoke(): RouterFunction { init() - return routes.reduce(RouterFunction::and) + return if (routes.isEmpty()) { + RouterFunction { Mono.empty() } + } + else { + routes.reduce(RouterFunction::and) + } } } \ No newline at end of file diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt index ce32b91b771..9fb5f20ccef 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt @@ -120,6 +120,11 @@ class RouterFunctionDslTests { .verifyComplete() } + @Test + fun emptyRouter() { + router { } + } + private fun sampleRouter() = router { (GET("/foo/") or GET("/foos/")) { req -> handle(req) }