exegesis-express provides Express middleware for handling OpenAPI 3.x API definitions, acting as a wrapper around the core `exegesis` library. It offers full support for OpenAPI 3.x.x features including request body parsing (JSON, form-urlencoded), response validation, authentication, and extensibility via a plugin system and custom format validation. The current stable version is 4.0.0, released in December 2021. While not on a fixed release cadence, it typically updates in conjunction with its parent `exegesis` library, incorporating bug fixes, security patches, and Node.js version support changes. Key differentiators include comprehensive OpenAPI 3.x conformance, flexible middleware placement, and robust error handling for API-driven applications.
npm install exegesis-expressVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up an Express server using `exegesis-express` to serve a simple OpenAPI 3.x defined API. It demonstrates how to initialize the middleware with an OpenAPI specification (inline JSON for simplicity), configure controllers, handle response validation errors, and correctly place the middleware within the Express stack.
Upgrade your Node.js version to 12.x or later. For continued Node.js 10 support, pin `exegesis-express` to a version prior to 4.0.0.
Review any code that parses or displays validation error messages to ensure compatibility with the new `ajv` messages. Update tests as necessary.
Upgrade your Node.js version to 8.x or later. For continued Node.js 6 support, pin `exegesis-express` to a version prior to 2.0.0.
Ensure `app.use(exegesisMiddleware)` is called before `app.use(express.json())` or similar body parsers. If a body parser runs first, `exegesis-express` will attempt to use `req.body` if it exists.
Add `x-exegesis-controller: 'YourControllerName'` and `operationId: 'yourOperationFunction'` to your OpenAPI path operations, and ensure `options.controllers` points to the directory containing `YourControllerName.js` (or `.ts`).
Verify that `options.controllers` in your middleware setup points to the correct directory. Confirm that the controller file exists and exports a function with the exact `operationId` name (e.g., `export function myOperation(...)`). Check the `x-exegesis-controller` value in your OpenAPI definition matches the controller file name (without extension).
Review your OpenAPI specification to ensure that parameters are correctly defined with their `in` property (e.g., `in: 'query'`, `in: 'path'`) and that your controller code correctly accesses them (e.g., `context.params.query.myParam`). Add `required: true` to OpenAPI parameters if they are mandatory.
Compare the data structure and types returned by your controller's operation function against the OpenAPI response schema (`paths['/your-path'].get.responses['200'].content['application/json'].schema`). Adjust either your controller's return value or the OpenAPI schema to match. If `onResponseValidationError` is set, its callback will be invoked.