Nested Tapir-ZIO-routes return 404 always

I have a set of Tapir ZServerEndpoint which I want to include in a zio-http server which also runs other, non-tapir defined endpoints. When I add them as-is it works as expected but when I try to serve the routes at a different root (nested routes), it always returns a 404.
When I print all routePatterns the routes are as expected but somehow the behaviour does not reflect this.
I am wondering if I am doing something wrong or if the Tapir conversion add some strict root-path checks?

Small example:

val tapirRoutes = ZioHttpInterpreter().toHttp(endpoint.in("foo").zServerLogic(_ => ZIO.unit))
val allRoutes = tapirRoutes ++ (literal("bar") / tapirRoutes)

When calling /foo I get an OK response but when I call /bar/foo it returns a 404.
Why would this happen?

Hm we have a test for this, looks very similar: tapir/server/zio-http-server/src/test/scala/sttp/tapir/server/ziohttp/ZioHttpCompositionTest.scala at master · softwaremill/tapir · GitHub

(and it passes :wink: )

Ah wait, I didn’t read it carefully enough, you use a different root path.

Adam, do you have any idea what could cause this? I am happy to try and fix it if it really is a bug but I do not really know where to look for this one. Perhaps you can help me get kick-started and point me to some relevant lines-of-code?

I suspect it might be something with pattern generation & request path consumption in ZioHttpInterpreter. Maybe we’re using the entire request path to do the matching, not the “unconsumed” path? I’d start looking there.

Test to reproduce: test: adding nested native zio route with tpiar routes test by ThijsBroersen · Pull Request #4814 · softwaremill/tapir · GitHub
Now I can try and fix it.

I made an initial fix/hack: Fix/nesting-native-zio-path-with-tapir-routes by ThijsBroersen · Pull Request #4815 · softwaremill/tapir · GitHub
I don’t think it can be done in a better way atm. And this fix would mean each endpoint call will at least have one addition pattern.matches check, which over course is overhead.