Converts standard JSON Schema (draft-07, 2019-09, 2020-12) to an OpenAPI v3.0.x compatible Schema Object. Current stable version is 0.5.0, released irregularly with breaking changes (v0.3.0 removed built-in $ref handling). Key differentiators: focused solely on v3.0.x compatibility (not v3.1.x), handles specific JSON Schema features unsupported by v3.0.x — converting items from array to object, multiple types to oneOf, const to enum, null type to nullable, and default values to proper OpenAPI types. Does NOT dereference $ref; users must pre-process with a separate dereferencing library. Lightweight with no runtime dependencies.
npm install json-schema-for-openapiNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Converts a JSON Schema with multiple unsupported patterns (array items, null type, const) to OpenAPI v3.0.x compatible schema object.
Pre-process your schema with @apidevtools/json-schema-ref-parser: const dereferenced = await $RefParser.dereference(schema);
Use import { convertSchemaObj } instead of import convertOpenApi.Ensure array items are either a single schema object or only one schema in the array. Manually merge if needed.
Use a dereferencing library to flatten schemas before conversion, and check for circular refs.
Dereference the schema first: const deref = await $RefParser.dereference(schema); then call convertSchemaObj(deref);
Change to: import { convertSchemaObj } from 'json-schema-for-openapi';Ensure input is standard JSON Schema; if necessary, manually convert items array to a single object before calling the library.