Skip to content

Swagger UI does not work in a kubernetes nginx-ingress setup #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gjgarryuan opened this issue Apr 3, 2020 · 1 comment
Closed

Swagger UI does not work in a kubernetes nginx-ingress setup #534

gjgarryuan opened this issue Apr 3, 2020 · 1 comment

Comments

@gjgarryuan
Copy link

I don't think this is a bug on the springdoc's side, but rather some unusability with the setup of kubernetes nginx-ingress + webapp with springdoc.

The observation is as follows:

  1. Browser visits https://some-host-name/some/path/prefix/swagger-ui.html
  2. Browser gets back HTTP 307 to redirect to /webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config
  3. Browser visits https://some-host-name/webjars/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config

As step 3 above, the configured nginx-ingress does not recognize the path as it does not start with the /some/path/prefix, hence redirect the request to the nginx home page.

The nginx-ingress is configured with:

{
    "apiVersion": "extensions/v1beta1",
    "kind": "Ingress",
    "metadata": {
        "annotations": {
            "kubernetes.io/ingress.class": "nginx-private",
            "nginx.ingress.kubernetes.io/rewrite-target": "/$2"
        },
        "name": "some-ingress",
        "namespace": "some-namespace"
    },
    "spec": {
        "rules": [
            {
                "host": "some-host-name",
                "http": {
                    "paths": [
                        {
                            "backend": {
                                "serviceName": "webapp-service",
                                "servicePort": 80
                            },
                            "path": "/some/path/prefix(/|$)(.*)"
                        }
                    ]
                }
            }
        ]
    }
}

I'm not sure if you have any solution for this kind of setup?

Screenshots
Screen Shot 2020-04-02 at 8 58 34 PM

Additional context
Add any other context about the problem here.

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Apr 4, 2020

@garrychnca,

There is no issue on getting swagger-ui using kubernetes.

You didn't mentionne, if you are using spring-mvc or spring-webflux.
You didn't mentionne the springdoc-openapi version you are using. Be sure you use the last stable version: v1.3.0

You can have the look at the following section: How can I deploy the Deploy springdoc-openapi-ui, behind a reverse proxy?

There is configuratino needed on your spring-boot application level first.

Additionally, you need to set the right headers depending on your reverse-proxy to make sure you forward X-Forwarded-Prefix:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants