springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot

Home Page:https://springdoc.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger UI webflux webjars location with application context

stuartkemp-e opened this issue · comments

Describe the bug

I have a webflux project which has a context-path set within spring config, and an additional context set externally (dev, staging, prod). The path I access swagger ui on locally is http://localhost:9990/my-app/swagger-ui/index.html. When I deploy to my server the path will be https://mydomain/dev/my-app/swagger-ui/index.html.

Swagger UI on my server fails to load because webjars are trying to be loaded from https://mydomain/my-app/webjars/swagger-ui/, which does not have the external context set (i.e. /dev).

I am aware of the springdoc.webjars.prefix option. If I set this to /dev/webjars, the path for the webjars becomes https://mydomain/my-app/dev/webjars/swagger-ui/, which is not correct in my case.

I have similar MVC applications. For these applications I can use configuration options to solve the problem (which manifests for swagger-config rather than webjars) like this:

springdoc:
  swagger-ui:
    config-url: /dev/my-app/swagger-config

In this case I can specify a complete path, but the webjars prefix does not work in the same way and does not solve my problem.

I have seen a similar issue here:
#24
But this user did not have an application context, but rather just a swagger context.

I have also seen this issue:
#1109
This user was able to fix the problem by having their proxy forward the X-Forwarded-Prefix header. Unfortunately I do not have any control over my reverse proxy so this is not an option for me. I am deploying onto kubernetes and I can pass this header in using ingress rules. However, kubernetes ingress does not support variables, and I could only pass in a fixed value. Since my external context (dev, staging, prod) varies, this is not an option either.

Are there any other options for specifying the absolute path of my webjar file?

To Reproduce

  • What version of spring-boot you are using? 3.2.4
  • What modules and versions of springdoc-openapi are you using? 2.4.0

Expected behavior

I am looking for an option to specify the location of my webjars with an externally set context, that does not require me to update a reverse proxy.