Gathering detailed insights and metrics for @openapi-contrib/json-schema-to-openapi-schema
Gathering detailed insights and metrics for @openapi-contrib/json-schema-to-openapi-schema
Gathering detailed insights and metrics for @openapi-contrib/json-schema-to-openapi-schema
Gathering detailed insights and metrics for @openapi-contrib/json-schema-to-openapi-schema
Due to the OpenAPI v3.0 and JSON Schema discrepancy, you can use this JS library to convert JSON Schema objects to OpenAPI Schema.
npm install @openapi-contrib/json-schema-to-openapi-schema
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (90.98%)
JavaScript (9.02%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
120 Stars
119 Commits
17 Forks
4 Watchers
3 Branches
2 Contributors
Updated on Jun 06, 2025
Latest Version
4.0.2
Package Id
@openapi-contrib/json-schema-to-openapi-schema@4.0.2
Unpacked Size
28.73 kB
Size
7.83 kB
File Count
10
NPM Version
10.9.2
Node Version
24.1.0
Published on
Jun 06, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A little NodeJS package to convert JSON Schema to a OpenAPI Schema Object.
type: ['foo', 'null']
to type: foo
and nullable: true
allOf
s etc.patternProperties
to x-patternProperties
dependencies
to an allOf + oneOf OpenAPI-valid equivalent1npm install --save @openapi-contrib/json-schema-to-openapi-schema
Requires NodeJS v10 or greater.
Here's a small example to get the idea:
1import { convert } from '@openapi-contrib/json-schema-to-openapi-schema'; 2 3const schema = { 4 $schema: 'http://json-schema.org/draft-04/schema#', 5 type: ['string', 'null'], 6 format: 'date-time', 7}; 8 9(async () => { 10 const convertedSchema = await convert(schema); 11 console.log(convertedSchema); 12})();
The example prints out
1{ 2 type: 'string', 3 format: 'date-time', 4 nullable: true 5}
The function accepts options
object as the second argument.
cloneSchema
(boolean)If set to false
, converts the provided schema in place. If true
, clones the schema by converting it to JSON and back. The overhead of the cloning is usually negligible. Defaults to true
.
dereference
(boolean)If set to true
, all local and remote references (http/https and file) $refs will be dereferenced. Defaults to false
.
convertUnreferencedDefinitions
(boolean)Defaults to true.
If a schema had a definitions property (which is valid in JSONSchema), and only some of those entries are referenced, we'll still try and convert the remaining definitions to OpenAPI. If you do not want this behavior, set this to false
.
dereferenceOptions
(object = $RefParser.Options)Options to pass to the dereferencer (@apidevtools/json-schema-ref-parser). To prevent circular references, pass { dereference: { circular: 'ignore' } }
.
1Usage: 2 json-schema-to-openapi-schema <command> [options] <file> 3 4Commands: 5 convert Converts JSON Schema Draft 04 to OpenAPI 3.0 Schema Object 6 7Options: 8 -h, --help Show help for any command 9 -v, --version Output the CLI version number 10 -d, --dereference If set all local and remote references (http/https and file) $refs will be dereferenced
OpenAPI is often described as an extension of JSON Schema, but both specs have changed over time and grown independently. OpenAPI v2 was based on JSON Schema draft v4 with a long list of deviations, but OpenAPI v3 shrank that list, upping their support to draft v4 and making the list of discrepancies shorter. This has been solved for OpenAPI v3.1, but for those using OpenAPI v3.0, you can use this tool to solve the divergence.
This tool sets out to allow folks to convert from JSON Schema (their one source of truth for everything) to OpenAPI (a thing for HTML docs and making SDKs).
† Draft v5 is also known as Draft Wright 00, as the drafts are often named after the author, and this was the first one by A. Wright. Amongst other things, draft v5 aimed to rewrite the meta files, but the experiment failed, meaning we need to continue to use the draft v4 metafiles. Ugh.
To convert the other way, check out openapi-schema-to-json-schema, which this package was based on.
To run the test-suite:
1npm test
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
5 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 14/30 approved changesets -- score normalized to 4
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More