swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
25.96k stars 8.85k forks source link

Swagger Server URL loads previously requested url basePath but logs show correct value #10024

Open parth-patil-uipath opened 1 week ago

parth-patil-uipath commented 1 week ago

Seems some cache issue when loading the swagger UI page when we update server url value dynamically with each /api-doc load page. Is this expected? amI missing something. Logs do show that I am updating the url with correct value and swagger.json page also shows correct url but UI page shows one from previously accessed url.

Q&A (please complete the following information)

Content & configuration

So basically I have trying to update the Swagger server every time I load /api-doc path. I am using ExpressJS framework for it. I am using following dependencies "swagger-jsdoc": "^4.0.0", "swagger-ui-express": "^4.6.3"

Server url value is loaded like this in certain way

apiDocRouter.use("/", swaggerUi.serve); apiDocRouter.get("/", async function(req, res) { res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); res.setHeader("Pragma", "no-cache"); res.setHeader("Expires", 0); // here update the url with what is coming from req path await formatOptions(req); logger.info(options json used in swagger is : ${JSON.stringify(options)});

const specs = await swaggerJSDoc(options); swaggerUi.setup(specs)(req, res); });

Swagger/OpenAPI definition:

# your YAML here

Any YAML file is fine. I am trying to update url through swagger specs

Swagger-UI configuration options:

SwaggerUI({
  // your config options here
})

let options = { definition: { openapi: "3.0.0", components: {}, security: { bearerAuth: [] }, servers: [ { url: "api/v1/openapi/" } ], info: { title: "XYZ API", version: "1.0.0", description: "" } }, / Path to the API docs/ apis: apisPaths };

?yourQueryStringConfig

Screenshots

UI page that loads server does not have correct url from swagger.json server. I see logs also update the server value correctly but it does not get reflected into UI. UI shows up the one from previously accessed url and this is randomly happening not persistent for all users.

How can we help?

Is this a known issue? Is there any other way where I can update server which has dynamic part and not only static path? I want to update server on each local of /api-doc (swagger UI page)