Are multiple routers under a single endpoint possible?

Hello, I have a question regarding how phoenix_swagger mentions in their docs that one can have multiple routers as in the following code:
config :my_app, :phoenix_swagger,
swagger_files: %{
“booking-api.json” => [router: MyApp.BookingRouter],
“reports-api.json” => [router: MyApp.ReportsRouter]
I am able to indeed generate 2 separate swaggers for 2 routers, but I cannot find anywhere in the phoenix documentation how I would have 2 routers under the same endpoint. When I place
plug MyApp.BookingRouter
plug MyApp.ReportsRouter
in endpoint.ex, only one is used.
The question is: how is phoenix_swagger intending this feature to be used?

You would forward from the parent router to a child router. So you would still have a single router plug in endpoint.ex, but it would be able to forward requests to another router plug inside itself.

1 Like

Thanks, that did the trick.

I think you can find this post very interesting

The reason why forward is not good (from the doc) option

Note, however, that we don’t advise forwarding to another
endpoint. The reason is that plugs defined by your app
and the forwarded endpoint would be invoked twice, which
may lead to errors.

I didn’t suggest forwarding to an endpoint, but to a router. forward is perfectly fine there. match would do the same thing when used to forward to another endpoint.