express-openapi is an unopinionated framework designed to integrate OpenAPI (formerly Swagger) specifications into Express.js applications. It currently supports OpenAPI versions 2.0 and 3.0. The library prioritizes performance and extensive testing, aiming to keep development as close to native Express patterns as possible while providing robust API documentation and validation capabilities. It achieves its features, such as parameter defaults, type coercion, request/response validation, and security handling, by leveraging a suite of modular `openapi-*` packages. The current stable version is 12.1.3. While not explicitly stating a release cadence, its version history suggests active development. Key differentiators include its flexible, unobtrusive design, comprehensive middleware configuration via vendor extensions, and the ability to maintain API documentation in sync with application code.
npm install express-openapiVerified import paths — ran on the pinned version, not inferred.
Sets up an Express server, initializes `express-openapi` with an in-memory OpenAPI 3.0 specification, defines a simple '/hello' endpoint, and serves Swagger UI for API exploration. This demonstrates basic setup, routing, and documentation generation.
Review Express 5 migration guides, especially for route definitions and regular expressions. Test thoroughly after upgrading Express. Ensure `path-to-regexp` is compatible or consider pinning its version if issues arise.
If encountering `SyntaxError: Invalid regular expression` related to route paths, explicitly pin the `glob` dependency to version `7.x.x` in your `package.json` using `resolutions` (for Yarn) or `overrides` (for npm) to force an older, compatible version of `glob`.
Always use an OpenAPI diff tool (e.g., `openapi-changes`, `spectral diff`) to compare your old and new API definitions before deploying. Communicate breaking changes to API consumers and provide migration guides. Ensure your client-side code is compatible with the new specification.
Refer to the `express-openapi` documentation for the specific version you are using to confirm the current behavior and supported vendor extensions for middleware configuration. Test your middleware chain thoroughly after any updates.
Add `"resolutions": { "glob": "7.x.x" }` (for Yarn) or `"overrides": { "glob": "7.x.x" }` (for npm) to your `package.json` to force an older, compatible version of `glob`.Review the exact validation error messages (often available in the response body or server logs). Adjust the client request to match the API's OpenAPI definition, or update the `apiDoc` if the specification is incorrect.
Ensure `initialize({ ..., docsPath: '/your-docs-path' })` matches `app.use('/your-docs-path', swaggerUi.serve, swaggerUi.setup(apiDoc));`. Verify `apiDoc` is a valid OpenAPI document with at least `info` and `openapi` fields.