@amritk/helpers 0.15.1 → 0.15.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.
|
@@ -159,8 +159,8 @@ const patternPropertiesRecordType = (patternProperties, options) => {
|
|
|
159
159
|
const getTuplePositions = (schema) => {
|
|
160
160
|
const record = schema;
|
|
161
161
|
const prefixItems = record["prefixItems"];
|
|
162
|
-
if (Array.isArray(prefixItems)
|
|
163
|
-
return prefixItems;
|
|
162
|
+
if (Array.isArray(prefixItems))
|
|
163
|
+
return prefixItems.length > 0 ? prefixItems : void 0;
|
|
164
164
|
if (Array.isArray(schema.items) && schema.items.length > 0)
|
|
165
165
|
return schema.items;
|
|
166
166
|
return void 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DATA_KEYWORDS } from "./build-resource-registry.js";
|
|
1
2
|
import { assertSchemaDepth } from "./max-schema-depth.js";
|
|
2
3
|
import { refToFilename, toKebabCase } from "./ref-to-filename.js";
|
|
3
4
|
const isDraft07Schema = (schema) => typeof schema["$schema"] === "string" && schema["$schema"].includes("draft-07");
|
|
@@ -72,10 +73,29 @@ const upgradeDraft07Schema = (schema) => {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
return {
|
|
75
|
-
...rest,
|
|
76
|
+
...rewriteDefinitionsRefs(rest),
|
|
76
77
|
$defs: hoistedDefs
|
|
77
78
|
};
|
|
78
79
|
};
|
|
80
|
+
const rewriteDefinitionsRefs = (obj, depth = 0) => {
|
|
81
|
+
assertSchemaDepth(depth, "upgradeDraft07Schema");
|
|
82
|
+
if (typeof obj !== "object" || obj === null)
|
|
83
|
+
return obj;
|
|
84
|
+
if (Array.isArray(obj))
|
|
85
|
+
return obj.map((item) => rewriteDefinitionsRefs(item, depth + 1));
|
|
86
|
+
const record = obj;
|
|
87
|
+
const result = {};
|
|
88
|
+
for (const [key, value] of Object.entries(record)) {
|
|
89
|
+
const rewritten = key === "$ref" && typeof value === "string" && value.startsWith("#/definitions/") ? value.replace("#/definitions/", "#/$defs/") : DATA_KEYWORDS.has(key) || startsNewResource(value) ? value : rewriteDefinitionsRefs(value, depth + 1);
|
|
90
|
+
if (key === "__proto__") {
|
|
91
|
+
Object.defineProperty(result, key, { value: rewritten, writable: true, enumerable: true, configurable: true });
|
|
92
|
+
} else {
|
|
93
|
+
result[key] = rewritten;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
};
|
|
98
|
+
const startsNewResource = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && typeof value["$id"] === "string";
|
|
79
99
|
const renameNestedDefs = (obj, depth = 0) => {
|
|
80
100
|
assertSchemaDepth(depth, "upgradeDraft07Schema");
|
|
81
101
|
if (typeof obj !== "object" || obj === null)
|