@json-schema-tools/dereferencer
Advanced tools
Comparing version 1.4.2 to 1.5.0
import { JSONSchema } from "@json-schema-tools/meta-schema"; | ||
import { ProtocolHandlerMap } from "@json-schema-tools/reference-resolver/build/reference-resolver"; | ||
export interface RefCache { | ||
@@ -18,2 +19,6 @@ [k: string]: JSONSchema; | ||
rootSchema?: JSONSchema; | ||
/** | ||
* Setup custom protocol handlers. See https://github.com/json-schema-tools/reference-resolver for details | ||
*/ | ||
protocolHandlerMap?: ProtocolHandlerMap; | ||
} | ||
@@ -20,0 +25,0 @@ /** |
@@ -118,2 +118,8 @@ "use strict"; | ||
} | ||
if (this.options.protocolHandlerMap) { | ||
for (var _i = 0, _a = Object.keys(this.options.protocolHandlerMap); _i < _a.length; _i++) { | ||
var k = _a[_i]; | ||
reference_resolver_1.default.protocolHandlerMap[k] = this.options.protocolHandlerMap[k]; | ||
} | ||
} | ||
this.schema = schema; // shallow copy breaks recursive | ||
@@ -157,10 +163,13 @@ this.refs = this.collectRefs(); | ||
if (!(ref === "#")) return [3 /*break*/, 3]; | ||
if (this.options.rootSchema === undefined) { | ||
throw new Error("options.rootSchema was not provided, but one of the schemas references '#'"); | ||
} | ||
fetched = this.options.rootSchema; | ||
return [3 /*break*/, 5]; | ||
case 3: | ||
refProm = reference_resolver_1.default(ref, this.options.rootSchema); | ||
refProm = reference_resolver_1.default.resolve(ref, this.options.rootSchema); | ||
proms.push(refProm); | ||
return [4 /*yield*/, refProm]; | ||
case 4: | ||
fetched = _a.sent(); | ||
fetched = (_a.sent()); | ||
_a.label = 5; | ||
@@ -167,0 +176,0 @@ case 5: |
@@ -0,1 +1,13 @@ | ||
# [1.5.0](https://github.com/json-schema-tools/dereferencer/compare/1.4.2...1.5.0) (2021-05-10) | ||
### Bug Fixes | ||
* update to latest reference-resolver ([a238336](https://github.com/json-schema-tools/dereferencer/commit/a2383361c2b2aac2078ac854a71ba8ff0188ba75)) | ||
### Features | ||
* add custom protocol handling ([593b400](https://github.com/json-schema-tools/dereferencer/commit/593b4009e9f0724c03a798ccf9f319db647ab68b)) | ||
## [1.4.2](https://github.com/json-schema-tools/dereferencer/compare/1.4.1...1.4.2) (2021-05-10) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "@json-schema-tools/dereferencer", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "Dereference (aka parse refs) from JSON Schemas", | ||
@@ -43,3 +43,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"@json-schema-tools/reference-resolver": "^1.0.7", | ||
"@json-schema-tools/reference-resolver": "^1.2.1", | ||
"@json-schema-tools/traverse": "^1.7.5", | ||
@@ -46,0 +46,0 @@ "fast-safe-stringify": "^2.0.7" |
@@ -54,3 +54,3 @@ # JSON Schema Dereferencer | ||
baz: { $ref: "../myschemas/baz.json" }, | ||
jsonSchemaMetaSchema: { $ref: "https://raw.githubusercontent.com/json-schema-tools/meta-schema/master/meta-schema.json" } | ||
jsonSchemaMetaSchema: { $ref: "https://meta.json-schema.tools" } | ||
}, | ||
@@ -72,4 +72,27 @@ additionalProperties: { | ||
### Add custom protocol handling | ||
```typescript | ||
import JsonSchemaDereferencer from "@json-schema-tools/dereferencer"; | ||
const mySchema = { | ||
type: "object", | ||
properties: { | ||
foo: { $ref: "ipfs://39420398420384" } | ||
} | ||
}; | ||
const dereferencer = new JsonSchemaDereferencer(mySchema, { | ||
protocolHandlerMap: { | ||
"ipfs": (ref) => Promise.resolve({ type: "string", title: "pretend we got this from ipfs" }) | ||
}); | ||
console.log(dereferencer.resolveSync()); | ||
console.log(await dereferencer.resolve()); | ||
``` | ||
### Contributing | ||
How to contribute, build and release are outlined in [CONTRIBUTING.md](CONTRIBUTING.md), [BUILDING.md](BUILDING.md) and [RELEASING.md](RELEASING.md) respectively. Commits in this repository follow the [CONVENTIONAL_COMMITS.md](CONVENTIONAL_COMMITS.md) specification. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44317
334
97