Converts Joi validation schemas into OpenAPI 3.0 schema definitions. Stable version 6.2.0, maintained on npm, with TypeScript definitions included. Key differentiator: directly maps Joi constraints (min, max, pattern, enum, nullable, etc.) to OpenAPI properties and supports `ref` components via a second argument. Requires Joi >=17.1.1 as a peer dependency. Alternative to manual OpenAPI schema authoring, useful for API documentation generators and validators that reuse existing Joi definitions.
npm install joi-to-swaggerNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a typical Joi user object schema into OpenAPI 3.0 schema definition, showing required fields, string format, nullable, and default.
Pass in a components object if you need to reference existing definitions; otherwise omit.
Add .meta({ className: 'MyModel' }) to Joi object schemas you want as reusable components.Upgrade Node.js to >=10 and Joi to >=17.1.1.
Use the returned schema directly; consider renaming variable to 'openApi' for clarity.
Manually verify converted schemas for alternatives; file an issue on GitHub if broken.
Run npm install joi-to-swagger joi
Use const j2s = require('joi-to-swagger'); or import j2s from 'joi-to-swagger';Check supported types in README; omit unsupported types or convert manually.
Pass a valid Joi schema (e.g., Joi.object({...})).