scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.43k stars 228 forks source link

Fix `serveFiles` to work w/ dynamic swaggerDoc #336

Closed chgeo closed 1 year ago

chgeo commented 1 year ago

serveFiles did not respect on-the-fly changes in a swagger doc, but rendered the old content.

The fix now also enables this pattern, where serveFiles doesn't need the swaggerDoc upfront (which is desired in dynamic cases):

app.use('/api-docs-dynamic', function(req, res, next){
  swaggerDocument.info.description = `Hello ${count}!`;
  req.swaggerDoc = swaggerDocument;
  next();
}, swaggerUi.serveFiles(), swaggerUi.setup());
//                     ^^^

Also fixes #318 which stumbled over the same issue, but draw the wrong conclusion that the documentation would be wrong.

chgeo commented 1 year ago

@scottie1984 Can you review?