Skip to content

How to document dynamic routes (app.use()) with express-openapi? #73

Description

@tit

I’m using express-openapi to generate OpenAPI documentation for my Express.js API. However, I’m unsure how to properly document dynamic routes that are mounted using app.use(), such as:

app.use((request, response, next) => {
  if (request.path.startsWith('/_admin')) {
    return next()
  }


  const rule = Database.query('SELECT ...')

  response
    .status(rule.status)
    .send(rule.responseBody)
}

What I’ve Tried:
Manually adding paths to openapi.json, but the file gets overwritten by the library.
Searching the documentation for dynamic route support but found no clear guidance.

Questions:
Is there a way to document these routes using JSDoc annotations?
Alternatively, can I define them in a separate YAML/JSON file that express-openapi will merge?

Environment:
express-openapi version: 1.1.0
Express.js version: 5.1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions