Skip to content

Commit 48c660f

Browse files
committed
Add support for empty router in RouterFunctionDsl
Issue: SPR-17247
1 parent f8a0e3d commit 48c660f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDsl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ open class RouterFunctionDsl(private val init: RouterFunctionDsl.() -> Unit) : (
546546
*/
547547
override fun invoke(): RouterFunction<ServerResponse> {
548548
init()
549-
return routes.reduce(RouterFunction<ServerResponse>::and)
549+
return if (routes.isEmpty()) {
550+
RouterFunction<ServerResponse> { Mono.empty() }
551+
}
552+
else {
553+
routes.reduce(RouterFunction<ServerResponse>::and)
554+
}
550555
}
551556

552557
}

spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/RouterFunctionDslTests.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ class RouterFunctionDslTests {
120120
.verifyComplete()
121121
}
122122

123+
@Test
124+
fun emptyRouter() {
125+
router { }
126+
}
127+
123128

124129
private fun sampleRouter() = router {
125130
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }

0 commit comments

Comments
 (0)