Marteng
Marteng

Reputation: 1305

How to prepend segments to OpenAPI paths?

I created a REST endpoint following this guide: https://quarkus.io/guides/rest-json

Locally I can successfully use swagger UI on <host>/q/swagger-ui which uses <host>/q/openapi as input. So far so good.

However, in production, I use Nginx to forward the requests to <host>/foobar. Thus, the final URLs change to <host>/foobar/q/swagger-ui and <host>/foobar/q/openapi.

nginx.conf snippet where the Quarkus Docker container is running on port 49321:

         location /foobar/ {
              proxy_pass  http://172.17.0.1:49321/;
         }

In the application.properties I already added the following line:

quarkus.swagger-ui.urls.direct=/foobar/q/openapi

By doing this, Swagger-UI finds the OpenAPI spec. But the OpenAPI spec contains the wrong URLs because it doesn't know about the /foobar/ URL segment.

How the OpenAPI looks:

---
paths:
  /some/url:
    get:
      tags:
      - blabla
      responses:
        "200":
          description: OK

How it needs to look (/foobar/ prepended to path):

---
paths:
  /foobar/some/url:
    get:
      tags:
      - blabla
      responses:
        "200":
          description: OK

I already checked available OpenAPI properties on https://quarkus.io/guides/openapi-swaggerui#openapi but they seem to not solve my problem. Any ideas?

Upvotes: 0

Views: 164

Answers (1)

Marteng
Marteng

Reputation: 1305

I solved it by setting the following in the application.properties:

quarkus.http.root-path=/foobar

and configuring Nginx as follows (nginx.conf):

location /foobar {
        proxy_pass  http://172.17.0.1:49321/foobar;
}

Upvotes: 1

Related Questions