Gathering detailed insights and metrics for json-schema-resolver
Gathering detailed insights and metrics for json-schema-resolver
Gathering detailed insights and metrics for json-schema-resolver
Gathering detailed insights and metrics for json-schema-resolver
json-schema-ref-resolver
JSON schema reference resolver
@stoplight/json-ref-resolver
Recursively resolve JSON pointers and remote authorities.
@json-schema-tools/reference-resolver
Turns a $ref into a JSONSchema
json-schema-traverse
Traverse JSON Schema passing each schema object to callback
Resolve all your JSON Schema $refs to relative path
npm install json-schema-resolver
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
10 Stars
22 Commits
3 Forks
4 Watching
3 Branches
2 Contributors
Updated on 06 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-8.7%
92,888
Compared to previous day
Last week
-9.9%
509,557
Compared to previous week
Last month
37.9%
1,959,765
Compared to previous month
Last year
106.3%
19,695,865
Compared to previous year
Resolve all $refs
in your JSON schema!
This module will resolve the $ref
keyword against the externalSchemas
you will provide.
By resolving the $ref
keyword, means that you get back a single BIG inlined JSON schema that does not rely on any external schema.
If a reference is missing, it will not throw any error.
1npm install json-schema-resolver
This plugin support Node.js >= 10
The $ref
string is going to be modified to point to a local reference URI: #/definitions/<generated key>
.
Moreover, the definitions
keyword will be decorated with the external schemas to get only one JSON schema resolved as output.
By default the <generated key>
has the def-${index}
format.
You can customize it by passing a buildLocalReference
function as follows:
1const RefResolver = require('json-schema-resolver') 2 3const ref = RefResolver({ 4 clone: true, // Clone the input schema without changing it. Default: false, 5 buildLocalReference (json, baseUri, fragment, i) { 6 // the `json` that is being resolved 7 // the `baseUri` object of the schema. Its values is the parse result from https://www.npmjs.com/package/uri-js 8 // the `fragment` is the `$ref` string when the `$ref` is a relative reference 9 // the `i` is a local counter to generate a unique key 10 return `def-${i}` // default value 11 } 12}) 13 14const inputSchema = { 15 $id: 'http://example.com/SimplePerson', 16 type: 'object', 17 properties: { 18 name: { type: 'string' }, 19 address: { $ref: 'relativeAddress#' }, 20 houses: { type: 'array', items: { $ref: 'relativeAddress#' } } 21 } 22} 23 24const addresSchema = { 25 $id: 'relativeAddress', // Note: prefer always absolute URI like: http://mysite.com 26 type: 'object', 27 properties: { 28 zip: { type: 'string' }, 29 city: { type: 'string' } 30 } 31} 32 33const singleSchema = ref.resolve(inputSchema, { externalSchemas: [addresSchema] }) 34// inputSchema is untouched thanks to clone:true
singleSchema
will be like:
1{ 2 "$id": "http://example.com/SimplePerson", 3 "type": "object", 4 "properties": { 5 "name": { 6 "type": "string" 7 }, 8 "address": { 9 "$ref": "#/definitions/def-0" 10 }, 11 "houses": { 12 "type": "array", 13 "items": { 14 "$ref": "#/definitions/def-0" 15 } 16 } 17 }, 18 "definitions": { 19 "def-0": { 20 "$id": "relativeAddress", 21 "type": "object", 22 "properties": { 23 "zip": { 24 "type": "string" 25 }, 26 "city": { 27 "type": "string" 28 } 29 } 30 } 31 } 32}
When you have multiple schemas to resolve against a collection of shared schema you need to use this module with little changes.
This is needed to have all the same definitions path (#/definitions/<generated key>
) across all the
root schemas
1const ref = RefResolver({
2 clone: true, // Clone the input schema without changing it. Default: false
3 applicationUri: 'my-application.org', // You need to provide an unique URI to resolve relative `$id`s
4 externalSchemas: [addresSchema] // The schemas provided at the creation of the resolver, will be used evvery time `.resolve` will be called
5})
6
7const inputSchema = {
8 $id: 'http://example.com/SimplePerson',
9 type: 'object',
10 properties: {
11 name: { type: 'string' },
12 address: { $ref: 'relativeAddress#' },
13 houses: { type: 'array', items: { $ref: 'relativeAddress#' } }
14 }
15}
16
17// the resolved schema DOES NOT have definitions added
18const singleSchema = ref.resolve(inputSchema)
19const anotherResolvedSchema = ref.resolve(input_2_Schema) // resolve schemas within the same externalSchemas
20
21// to get the definition you need only to call:
22const sharedDefinitions = ref.definitions()
To debug this module, simply set:
1export DEBUG=json-schema-resolver
Licensed under MIT.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/22 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
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