# Combining different "mount points" in the same Swagger UI

**URL:** <https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194>\
**Category:** tapir\
**Created:** [May 8, 2023, 11:34pm UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194 "2023-05-08T23:34:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beneyal](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/beneyal/32/57_2.png) [@beneyal](https://softwaremill.community/u/beneyal)\
**Post date:** [May 8, 2023, 11:34pm UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194/1 "2023-05-08T23:34:29Z")

</div>

Hello 🙂

I currently have the following code:

```plaintext
  val rootSwaggerEndpoints = SwaggerInterpreter().fromServerEndpoints[MyIO](root.all, "My API", "1.0")
  val rootEndpoints = root.all ++ rootSwaggerEndpoints
  val apiv4SwaggerEndpoints = SwaggerInterpreter(swaggerUIOptions =
    SwaggerUIOptions.default.contextPath(List("api", "4"))
  ).fromServerEndpoints[MyIO](apiv4.all, "My API", "1.0")
  val apiv4Endpoints = apiv4.all ++ apiv4SwaggerEndpoints

  val rootRoutes: HttpRoutes[MyIO] = ZHttp4sServerInterpreter().from(rootEndpoints).toRoutes
  val apiv4Routes: HttpRoutes[MyIO] = ZHttp4sServerInterpreter().from(apiv4Endpoints).toRoutes
  val router: HttpRoutes[MyIO] = Router("/" -> rootRoutes, "/api/4" -> apiv4Routes)

```

This makes it so I have two `docs` endpoints, one mounted on `/` and one mounted on `/api/4`. Is there a nice way to make it so all endpoints appear in `/docs`, but have the `apiv4SwaggerEndpoints` have the `/api/4/` prefix to them? As you can see, I had to add a `contextPath` to my `apiv4SwaggerEndpoints`, as Swagger sent requests to `/`, even though the docs were on `/api/4`.

Thanks! 🙏

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 9, 2023, 7:33am UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194/2 "2023-05-09T07:33:36Z")

</div>

The context path setting is not relevant if you use relative paths. If I understand your desired layout correctly (you want to add a server to openapi which will point to /api/v4), this can be done by modifying the options as follows:

```auto
SwaggerUIOptions.default.contextPath(List("api", "4")).withAbsolutePaths

```

Let me know if this works 🙂

---

<div class="post-metadata">

**Author:** ![beneyal](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/beneyal/32/57_2.png) [@beneyal](https://softwaremill.community/u/beneyal)\
**Post date:** [May 9, 2023, 7:43am UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194/3 "2023-05-09T07:43:56Z")

</div>

Thanks for your replay, Adam!

Adding `.withAbsolutePaths` didn’t seem to do anything other than change the location of the YAML file, from what I can tell. I think I didn’t quite explain what I’m trying to do, so I’ll try again 🙂

Currently, I have two `docs` endpoints: `/api/4/docs` (shown below)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/softwaremill/original/1X/b25da9143da5462700453034c3b7a1ec8ea866f5.png)

And `/docs` (shown below)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/softwaremill/original/1X/87fb4510c660aacb2b4e50f2a9fe71d60c316a26.png)

What I’m trying to do is a have a single `docs` endpoint, to be mounted on the root route (so `/docs`), and that it will have the endpoints of both screenshots, with routes preceded with `/api/4` showing as such in Swagger.

Thanks again! 🙏

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [May 9, 2023, 4:50pm UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194/4 "2023-05-09T16:50:40Z")

</div>

Ah I see 🙂 I think the simples solution could be to generate the docs from endpoints which are prefixed with `api/v4`. Sth like:

```auto
val apiv4SwaggerEndpoints = SwaggerInterpreter()
  .fromEndpoints[IO](apiv4.map(_.endpoint.prependIn("api" / "v4")), "My API", "1.0")

```

Note that I don’t think you need the `contextPath` setting, as it’s a no-op in your case.

---

<div class="post-metadata">

**Author:** ![beneyal](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/beneyal/32/57_2.png) [@beneyal](https://softwaremill.community/u/beneyal)\
**Post date:** [May 9, 2023, 4:53pm UTC](https://softwaremill.community/t/combining-different-mount-points-in-the-same-swagger-ui/194/5 "2023-05-09T16:53:25Z")

</div>

Ah, that `_.endpoint.prependIn` was what I was missing! Thank you very much, Adam! And while I’m at it, tapir made a great impression at work today, after adding 3 lines of code and getting a documented Swagger UI for free 😉
