Registry / devops / openapi-json-schema

openapi-json-schema

JSON →
library2.0.0jsnpmunverified

Minimalistic OpenAPI 3 to JSON Schema (draft 7) conversion library. v2.0.0 is pure ESM, requires Node >=14.13.1. No dependencies. Supports nullable, $ref conversion between #/definitions and #/components/schemas, const to enum, $id/$comment to x-id/x-comment. Does not resolve JSON $refs. Differentiator: zero dependencies, focused conversion without resolution.

npm install openapi-json-schema
INSTALL
IMPORT
SIG · OPENAPI-JSON-SCHEM
O
openapi-json-schema
devopsjavascriptv2.0.0
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.

jsonSchemaToOpenApiSchema
import { jsonSchemaToOpenApiSchema } from 'openapi-json-schema'
const { jsonSchemaToOpenApiSchema } = require('openapi-json-schema')
ESM-only since v2; CommonJS require will fail.
openApiSchemaToJsonSchema
import { openApiSchemaToJsonSchema } from 'openapi-json-schema'
import openApiSchemaToJsonSchema from 'openapi-json-schema'
Named export, not default.
encodeRefNameJsonSchema
import { encodeRefNameJsonSchema } from 'openapi-json-schema'

Shows bidirectional conversion between JSON Schema and OpenAPI 3 schema using the two main exports.

import { jsonSchemaToOpenApiSchema, openApiSchemaToJsonSchema } from 'openapi-json-schema'; const jsonSchema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer' }, }, required: ['name'], nullable: true, }; // Convert to OpenAPI 3 schema const openApiSchema = jsonSchemaToOpenApiSchema(jsonSchema); console.log(JSON.stringify(openApiSchema, null, 2)); // Convert back to JSON Schema const backToJsonSchema = openApiSchemaToJsonSchema(openApiSchema); console.log(JSON.stringify(backToJsonSchema, null, 2));
Debug
Known issues
breakingv2.0.0 dropped CommonJS support; package is pure ESM.
fix
Use ESM imports (import ... from 'openapi-json-schema') or upgrade to Node >=14.13.1.
affects: >=2.0.0
gotchaJSON $refs are not resolved; only converted between #/definitions and #/components/schemas.
fix
Resolve $refs manually before conversion if needed.
affects: *
gotchaOnly supports JSON Schema draft 7; newer drafts (2019-09, 2020-12) features are not handled.
fix
Ensure your JSON Schema input is draft 7 compatible.
affects: *
deprecatedThe package is minimalistic and may not support all OpenAPI 3.1 features like full JSON Schema 2020-12.
fix
Consider alternative libraries if you need full OpenAPI 3.1 support.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package.
fix
Convert to ESM imports or use dynamic import() with CommonJS: const { jsonSchemaToOpenApiSchema } = await import('openapi-json-schema');
TypeError: jsonSchemaToOpenApiSchema is not a function
Using default import instead of named import.
fix
Change to: import { jsonSchemaToOpenApiSchema } from 'openapi-json-schema';
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
openapi-json-schema — npm install openapi-json-schema · libregistry