A library to convert Joi validation schemas to JSON Schema (Draft 04, 07, 2019-09, 2020-12) and OpenAPI 3.0/3.1 formats. Current stable version v5.0.5, released Nov 2024, supports Joi v17.13.3 and v18.0.0. Built on Joi's public describe() API, avoiding internal dependencies. Offers multiple output types via a single parse() function. Key differentiator: official Joi describe-based conversion with broad output standard support, unlike older libraries relying on private APIs.
npm install joi-to-jsonNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage converting a Joi schema to JSON Schema and OpenAPI, including custom definitions and options.
Upgrade Joi to v17.13.3+ or v18.0.0.
Pin joi-to-json and Joi to exact versions during development.
Avoid circular references or manually break the cycle with a maxDepth option (not available).
Add explicit Joi constraints (e.g., .valid(), .allow()) to produce meaningful schema.
Use 'open-api-3.1' for modern OpenAPI.
Use default import: import parse from 'joi-to-json'
Run 'npm install joi-to-json'. If using ESM, ensure package.json has 'type': 'module' or use .mjs extension.
Upgrade Joi: npm install joi@latest (at least 17.13.3)
Ensure first argument is a Joi schema created via Joi.object(), Joi.string(), etc.