Express middleware that validates request body, query, and params using Yup schemas. Version 2.0.0 is the latest stable release. It integrates Yup validation into Express routes and returns structured error responses. Differentiators include custom error messages per field, validation options per schema part (e.g., abortEarly), and cross-validation via context. Requires Yup as a peer dependency.
npm install express-yup-middlewareVerified import paths — ran on the pinned version, not inferred.
Basic Express route with body validation using Yup schema and custom error messages.
Ensure `schemaValidator` includes at least one of `body`, `query`, `params` inside `schema`.
Use the same string passed to Yup's validation message as the key in `errorMessages`.
Access `this.options.context` in Yup `.test()` to get the request payload.
Use Yup v1.x and import as `import * as Yup from 'yup'`.
Run `npm install express-yup-middleware` and use correct import: `import { expressYupMiddleware } from 'express-yup-middleware'`.Provide `schema` with at least one key (`body`, `query`, `params`) as shown in docs.
Ensure request body includes the required field defined in schema.