Skip to content

External context path is not respected when using Swagger UI #607

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
gcelikkaya opened this issue Apr 24, 2020 · 4 comments
Closed

External context path is not respected when using Swagger UI #607

gcelikkaya opened this issue Apr 24, 2020 · 4 comments

Comments

@gcelikkaya
Copy link

Version: springdoc-openapi-ui 1.3.4

If I deploy my application K8s with some custom path, swagger UI redirection does not work. It looks for the spring context path + springdoc.api-docs.path. So it does not work with relative paths.

Lets say I have:

server.servlet.context-path=/foo
springdoc.api-docs.path=/swagger/api
springdoc.swagger-ui.path=/swagger/ui

But with K8s and Ingress my application runs at http://api.someurl.com/my-custom-path/foo/ and http://api.someurl.com/my-custom-path/foo/swagger/api works fine

But when I visit http://api.someurl.com/my-custom-path/foo/swagger/ui it redirects to http://api.someurl.com/foo/swagger/swagger-ui/index.html?configUrl=/foo/swagger/api/swagger-config

So it removes my-custom-path from the redirected URL.

@bnasslahsen
Copy link
Collaborator

bnasslahsen commented Apr 24, 2020

@gcelikkaya,

If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:

  • Where is my-custom-path coming from ? which configuration ?
  • Additionnaly, is the configuration working fine outside your k8s ?
  • You need to describe your context (the title of an issue is not enough)
  • What version of spring-boot you are using?
  • What modules and versions of springdoc-openapi are you using?
  • What are the actual and the expected result ?

@gcelikkaya
Copy link
Author

@bnasslahsen thanks for your reply

  • Project is deployed via K8s and my-custom-path is added by Ingress.
  • The project is written with Spring Boot 2.2.2.
  • When the application runs locally everything works fine, there is no issue with URL redirection.
  • The only springdoc dependency I have is org.springdoc:springdoc-openapi-ui:1.3.4

Actually inside the pod it is running at http://localhost/swagger/api but Ingress exposes it to outside world on http://some-url/some-path/swagger/api

The problem here is that when I visit http://some-url/some-path/swagger/ui it redirects to http://some-url/swagger/swagger-ui/index.html?configUrl=/swagger/api/swagger-config where correct url would be http://some-url/some-path/swagger/swagger-ui/index.html?configUrl=/some-path/swagger/api/swagger-config. It removes some-path that Ingress defined. I expected it to understand the /some-path and redirect accordingly.

@bnasslahsen
Copy link
Collaborator

@gcelikkaya,

You should set the correct spring-boot properties and the configuration of your web server to forward the correct headers :

1)- On your spring-boot app, you should have:

server.forward-headers-strategy=framework

2)- You need to make sure the following header is set in your reverse proxy configuration (ingress in your case): X-Forwarded-Prefix

More details available here:

@gcelikkaya
Copy link
Author

gcelikkaya commented Apr 28, 2020

Indeed the issue was on my application. Thank you for your help. I fixed it as you suggested. I am closing this issue

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