@hyperjump/json-schema 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/bundle/index.js +5 -6
- package/lib/schema.js +21 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -592,8 +592,6 @@ These are available from the `@hyperjump/json-schema/experimental` export.
|
|
|
592
592
|
* includeDialect: "auto" | "always" | "never" (default: "auto") -- If
|
|
593
593
|
"auto", `$schema` will only be included if it differs from
|
|
594
594
|
`contextDialectId`.
|
|
595
|
-
* selfIdentify: boolean (default: false) -- If true, `$id` will be
|
|
596
|
-
included.
|
|
597
595
|
* contextUri: string (default: "") -- `$id`s will be relative to this
|
|
598
596
|
URI.
|
|
599
597
|
* includeEmbedded: boolean (default: true) -- If false, embedded schemas
|
package/bundle/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { v4 as uuid } from "uuid";
|
|
|
3
3
|
import * as Browser from "@hyperjump/browser";
|
|
4
4
|
import * as JsonPointer from "@hyperjump/json-pointer";
|
|
5
5
|
import { asyncCollectSet, asyncFilter, asyncFlatten, asyncMap, pipe } from "@hyperjump/pact";
|
|
6
|
-
import { resolveUri } from "@hyperjump/uri";
|
|
7
6
|
import {
|
|
8
7
|
Validation,
|
|
9
8
|
canonicalUri, getSchema, toSchema,
|
|
@@ -37,10 +36,13 @@ export const bundle = async (url, options = {}) => {
|
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
for (const uri of externalIds) {
|
|
39
|
+
if (fullOptions.externalSchemas.includes(uri)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
40
43
|
const externalSchema = await getSchema(uri);
|
|
41
44
|
const embeddedSchema = toSchema(externalSchema, {
|
|
42
|
-
|
|
43
|
-
contextUri: contextUri,
|
|
45
|
+
contextUri: externalSchema.document.baseUri.startsWith("file:") ? contextUri : undefined,
|
|
44
46
|
includeDialect: fullOptions.alwaysIncludeDialect ? "always" : "auto",
|
|
45
47
|
contextDialectId: contextDialectId
|
|
46
48
|
});
|
|
@@ -49,9 +51,6 @@ export const bundle = async (url, options = {}) => {
|
|
|
49
51
|
const idToken = getKeywordName(externalSchema.document.dialectId, "https://json-schema.org/keyword/id")
|
|
50
52
|
|| getKeywordName(externalSchema.document.dialectId, "https://json-schema.org/keyword/draft-04/id");
|
|
51
53
|
id = embeddedSchema[idToken];
|
|
52
|
-
if (id in JsonPointer.get(bundlingLocation, bundled)) {
|
|
53
|
-
id = resolveUri(id, contextUri);
|
|
54
|
-
}
|
|
55
54
|
} else if (fullOptions.definitionNamingStrategy === UUID) {
|
|
56
55
|
id = uuid();
|
|
57
56
|
} else {
|
package/lib/schema.js
CHANGED
|
@@ -206,6 +206,10 @@ const processSchema = (json, id, dialectId, cursor, embedded, anchors, dynamicAn
|
|
|
206
206
|
export const canonicalUri = (browser) => `${browser.document.baseUri}#${encodeURI(browser.cursor)}`;
|
|
207
207
|
|
|
208
208
|
export const toSchema = (browser, options = {}) => {
|
|
209
|
+
if (!options.contextUri && browser.document.baseUri.startsWith("file:")) {
|
|
210
|
+
options.contextUri = browser.document.baseUri;
|
|
211
|
+
}
|
|
212
|
+
|
|
209
213
|
const anchors = {};
|
|
210
214
|
for (const anchor in browser.document.anchors) {
|
|
211
215
|
if (anchor !== "" && !browser.document.dynamicAnchors[anchor]) {
|
|
@@ -237,9 +241,7 @@ export const toSchema = (browser, options = {}) => {
|
|
|
237
241
|
if (JSON.stringify(value.toJSON()) === "{}") {
|
|
238
242
|
return toSchema({ document: browser.document.embedded[toAbsoluteIri(value.href)] }, {
|
|
239
243
|
...options,
|
|
240
|
-
contextDialectId: browser.document.dialectId
|
|
241
|
-
selfIdentify: true,
|
|
242
|
-
contextUri: browser.document.baseUri
|
|
244
|
+
contextDialectId: browser.document.dialectId
|
|
243
245
|
});
|
|
244
246
|
} else {
|
|
245
247
|
return { [legacyRefToken]: value.href };
|
|
@@ -247,9 +249,7 @@ export const toSchema = (browser, options = {}) => {
|
|
|
247
249
|
} else if (options.includeEmbedded ?? true) {
|
|
248
250
|
return toSchema({ document: browser.document.embedded[toAbsoluteIri(value.href)] }, {
|
|
249
251
|
...options,
|
|
250
|
-
contextDialectId: browser.document.dialectId
|
|
251
|
-
selfIdentify: true,
|
|
252
|
-
contextUri: browser.document.baseUri
|
|
252
|
+
contextDialectId: browser.document.dialectId
|
|
253
253
|
});
|
|
254
254
|
} else {
|
|
255
255
|
return;
|
|
@@ -295,18 +295,25 @@ export const toSchema = (browser, options = {}) => {
|
|
|
295
295
|
}
|
|
296
296
|
|
|
297
297
|
// Self-identification
|
|
298
|
-
if (options.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
} else {
|
|
298
|
+
if (options.contextUri) {
|
|
299
|
+
const relativeUri = toRelativeIri(normalizeIri(options.contextUri), browser.document.baseUri);
|
|
300
|
+
if (relativeUri !== "") {
|
|
301
|
+
const id = schema[idToken] ? `${relativeUri}${schema[idToken]}` : relativeUri;
|
|
302
|
+
delete schema[idToken];
|
|
303
|
+
|
|
305
304
|
schema = {
|
|
306
|
-
[idToken]:
|
|
305
|
+
[idToken]: id,
|
|
307
306
|
...schema
|
|
308
307
|
};
|
|
309
308
|
}
|
|
309
|
+
} else if (!browser.document.baseUri.startsWith("file:")) {
|
|
310
|
+
const id = schema[idToken] ? `${browser.document.baseUri}${schema[idToken]}` : browser.document.baseUri;
|
|
311
|
+
delete schema[idToken];
|
|
312
|
+
|
|
313
|
+
schema = {
|
|
314
|
+
[idToken]: id,
|
|
315
|
+
...schema
|
|
316
|
+
};
|
|
310
317
|
}
|
|
311
318
|
|
|
312
319
|
// $schema
|