swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

How to fix URLs displayed in Swagger UI?

Open justincranford opened this issue 5 years ago • 3 comments

I am running my APIs with servlet path /restapis, and Swagger UI with servlet path /. My auto-generated /restapis/openapi.json renders in Swagger UI, but the paths are wrong.

  • Rendered URL => http://localhost:8443/resource1
  • Expected URL => http://localhost:8443/restapis/resource1

I am launching Jetty 9.4.22.v20191022 from a POJO. Context path is /, and there are two servlets.

  1. /restapis => Jersey 2.29.1 Servlet with init parameter (jersey.config.server.provider.classnames=io.swagger.v3.jaxrs2.integration.resources.OpenApiResource,com.example.rest.Resource1)
  2. / => Jetty Default Servlet with welcome files = {index.html}, and context base = unpacked Swagger UI 3.24.3 directory.

The unpacked index.html is modified to replace the default URL, similar to how https://github.com/swagger-api/swagger-ui/blob/master/docker/run.sh#L35 is substituting it.

  • Original => url: "https://petstore.swagger.io/v2/swagger.json"
  • Replacement => url: "http://localhost:8443/restapi/openapi.json"

In Swagger UI, I expect to see /restapis/resource1, but it shows /resource1 instead. If I use Swagger UI to try to execute that API, Swagger UI displays HTTP 404 response from the API.

justincranford avatar Dec 24 '19 05:12 justincranford