Add support for empty router in RouterFunctionDsl

Issue: SPR-17247
This commit is contained in:
Sebastien Deleuze 2018-09-05 16:53:59 +02:00
parent f8a0e3d084
commit 48c660fa41
2 changed files with 11 additions and 1 deletions

View File

@ -546,7 +546,12 @@ open class RouterFunctionDsl(private val init: RouterFunctionDsl.() -> Unit) : (
*/
override fun invoke(): RouterFunction<ServerResponse> {
init()
return routes.reduce(RouterFunction<ServerResponse>::and)
return if (routes.isEmpty()) {
RouterFunction<ServerResponse> { Mono.empty() }
}
else {
routes.reduce(RouterFunction<ServerResponse>::and)
}
}
}

View File

@ -120,6 +120,11 @@ class RouterFunctionDslTests {
.verifyComplete()
}
@Test
fun emptyRouter() {
router { }
}
private fun sampleRouter() = router {
(GET("/foo/") or GET("/foos/")) { req -> handle(req) }