Registry / testing / enjoi
library9.0.1jsnpmunverified

Converts JSON Schema to Joi schema for object validation. Stable v9.0.1 (latest), maintained with regular releases. Key differentiator: provides bidirectional conversion between JSON Schema (including OpenAPI) and Joi, supporting sub-schemas, custom types, and refinement functions. Minimal dependencies (only peer dep on joi 17+). Does not support all JSON Schema keywords (e.g., patternProperties).

npm install enjoi
INSTALL
IMPORT
SIG · ENJOI
E
enjoi
testingjavascriptv9.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Enjoi
const Enjoi = require('enjoi');
import { Enjoi } from 'enjoi';
CommonJS default export. In ESM, use: import Enjoi from 'enjoi';
schema
Enjoi.schema(jsonSchema, options);
const { schema } = require('enjoi'); schema(...);
schema is a static method, not a named export.
defaults
const enjoi = Enjoi.defaults(options);
Enjoi.defaults(options).schema(...);
defaults returns a new object with a schema method; does not mutate global state.

Converts a simple JSON Schema to a Joi schema and validates an object.

const Joi = require('joi'); const Enjoi = require('enjoi'); const jsonSchema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer', minimum: 0 } }, required: ['name'] }; const joiSchema = Enjoi.schema(jsonSchema); const result = joiSchema.validate({ name: 'Alice', age: 30 }); console.log(result.error); // null console.log(result.value); // { name: 'Alice', age: 30 }
Debug
Known issues
gotchaenjoi does not support all JSON Schema keywords; patternProperties is unsupported due to Joi limitations.
fix
Use additionalProperties or custom validation via refineSchema for unsupported keywords.
affects: >=0.0.0
breakingenjoi v9 drops support for Node <8; requires joi >=17.1.0 as peer dependency.
fix
Upgrade Node to >=8 and ensure joi >=17.1.0 is installed.
affects: >=9.0.0
deprecatedThe `subSchemas` option with `$ref` values using '#' prefix references the root schema; ensure correct path syntax.
fix
Use string referencing e.g., 'sub#/d' for sub-schemas; root is '#'.
affects: >=0.0.0
gotchaDefault export is a function (not a class or object) with static methods, not a constructor.
fix
Use Enjoi.schema() directly; do not call new Enjoi().
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Enjoi is not a constructor
Using `new Enjoi()` when Enjoi is a plain object with static methods.
fix
Use `Enjoi.schema(...)` instead of `new Enjoi(...)`.
Cannot find module 'joi'
Missing peer dependency joi.
fix
Run `npm install joi` to install joi >=17.1.0.
Unsupported schema keyword: patternProperties
enjoi does not support patternProperties due to Joi limitations.
fix
Use `additionalProperties` with a schema, or use `refineSchema` to add custom validation.
Upgrade
Version history
9.0.1latest on npm
Audit
Dependencies
joirequiredPeer dependency: enjoi generates Joi schemas and requires joi >=17.1.0 to be installed alongside.
Agent activity
9 hits · last 30 days
node
8
Resources
packageenjoi
enjoi — npm install enjoi · libregistry