# exframe-request-validator

> Validates requests and returns pretty(ish) error messages

Latest version **1.10.5** (published 2026-10-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install exframe-request-validator
pnpm add exframe-request-validator
yarn add exframe-request-validator
bun add exframe-request-validator
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.10.5 |
| Published | 2026-10-29 |
| First published | 2018-04-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 32.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Exzeo |
| Maintainers | exzeo_usa, exzeodevops |

## Links

- npm: https://www.npmjs.com/package/exframe-request-validator
- Repository: https://bitbucket.org/exzeo-usa/exframe
- Homepage: https://bitbucket.org/exzeo-usa/exframe#readme
- Issues: https://bitbucket.org/exzeo-usa/exframe/issues
- npm.io page: https://npm.io/package/exframe-request-validator

## Dependencies (3)

- [ajv](https://npm.io/package/ajv.md) ^8.11.2
- [ajv-errors](https://npm.io/package/ajv-errors.md) ^3.0.0
- [ajv-formats](https://npm.io/package/ajv-formats.md) ^2.1.1

## Recent versions

- 1.10.5 (latest) — 2026-10-29
- 1.10.4 — 2026-03-25
- 1.10.3 — 2025-02-24
- 1.10.2 — 2023-10-10
- 1.10.1 — 2023-09-13
- 1.10.0 — 2023-09-12
- 1.9.0 — 2023-09-07
- 1.8.0 — 2023-09-07
- 1.7.0 — 2023-07-12
- 1.6.0 — 2023-04-26
- 1.5.1 — 2023-03-24
- 1.5.0 — 2022-12-22
- 1.4.1 — 2022-08-31
- 1.4.0 — 2022-04-28
- 1.2.2 — 2019-07-17
- … 7 more at https://npm.io/package/exframe-request-validator/versions

## README

# exframe-request-validator
Wraps ajv to validate requests and produce human readable error messages when validation fails.

### Example - validate requests
```javascript
const validator = require('exframe-request-validator');

const sampleSchema = {
  $schema: 'http://json-schema.org/draft-07/schema#',
  title: 'Sample Validation Schema',
  type: 'object',
  required: [ 'thing1' ],
  properties: {
    thing1: { type: 'string' },
    thing2: { type: 'string', minLength: 1 }
  }
};

const validateSchema = (schema) => {
  const validate = validator.generateValidator(schema);

  return async (context, obj) => {
    validate({ log: context.log }, obj);
  };
};

return validateSchema(sampleSchema)(context, requestBody)
  .then(()) => {
    // Passed validation - do something awesome
  }
  .catch(err => {
    // One or more things failed validation.
    // err.status = 400
    // err.message = Human readable message
    // err.validationErrors = Array of validation failures
  });

```

custom error messages can also be used against specific properties / items
use https://github.com/epoberezkin/ajv-errors for reference

## Schema Dependencies

An optional second parameter can be passed to the `generateValidator()` function.
It must be an array of schema dependencies which will be added via `ajv.addSchema()`.
*Each of these schemas must contain an $id.*
More information about `addSchema()` can be [found here](https://ajv.js.org/api.html#ajv-addschema-schema-object-object-key-string-ajv).

### Example
```javascript
  const validate = validator.generateValidator(schema, [referenceSchema1, referenceSchema2]);
```

---
_Source: https://npm.io/package/exframe-request-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
