schema-components 1.12.1 → 1.12.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/dist/core/walker.mjs +24 -14
- package/package.json +1 -1
package/dist/core/walker.mjs
CHANGED
|
@@ -30,8 +30,10 @@ function resolveRef(schema, rootDocument, visited) {
|
|
|
30
30
|
return resolveRef(resolved, rootDocument, nextVisited);
|
|
31
31
|
}
|
|
32
32
|
function dereference(ref, root) {
|
|
33
|
+
if (ref === "#") return root;
|
|
33
34
|
if (!ref.startsWith("#/")) return void 0;
|
|
34
35
|
const parts = ref.slice(2).split("/");
|
|
36
|
+
if (parts.length === 1 && parts[0] === "") return root;
|
|
35
37
|
let current = root;
|
|
36
38
|
for (const part of parts) {
|
|
37
39
|
if (!isObject(current)) return void 0;
|
|
@@ -195,7 +197,8 @@ function walk(schema, options = {}) {
|
|
|
195
197
|
rootDocument: doc,
|
|
196
198
|
isNullable: false,
|
|
197
199
|
isOptional: false,
|
|
198
|
-
defaultValue: void 0
|
|
200
|
+
defaultValue: void 0,
|
|
201
|
+
visitedRefs: /* @__PURE__ */ new Set()
|
|
199
202
|
});
|
|
200
203
|
}
|
|
201
204
|
function walkNode(schema, ctx) {
|
|
@@ -216,25 +219,32 @@ function walkNode(schema, ctx) {
|
|
|
216
219
|
if (discriminated !== void 0) return walkDiscriminatedUnion(discriminated, ctx);
|
|
217
220
|
return walkUnion(oneOf, ctx);
|
|
218
221
|
}
|
|
219
|
-
const
|
|
222
|
+
const ref = getString(schema, "$ref");
|
|
223
|
+
if (ref !== void 0 && ctx.visitedRefs.has(ref)) return buildField(schema, "unknown", ctx);
|
|
224
|
+
const resolved = ref !== void 0 ? resolveRef(schema, ctx.rootDocument, /* @__PURE__ */ new Set()) : schema;
|
|
225
|
+
const childVisited = ref !== void 0 ? new Set([...ctx.visitedRefs, ref]) : ctx.visitedRefs;
|
|
226
|
+
const ctxWithRef = {
|
|
227
|
+
...ctx,
|
|
228
|
+
visitedRefs: childVisited
|
|
229
|
+
};
|
|
220
230
|
const enumValues = getArray(resolved, "enum");
|
|
221
|
-
if (enumValues !== void 0) return walkEnum(resolved, enumValues,
|
|
222
|
-
if ("const" in resolved) return walkLiteral(resolved,
|
|
231
|
+
if (enumValues !== void 0) return walkEnum(resolved, enumValues, ctxWithRef);
|
|
232
|
+
if ("const" in resolved) return walkLiteral(resolved, ctxWithRef);
|
|
223
233
|
const type = getString(resolved, "type");
|
|
224
|
-
if (type === void 0) return buildField(resolved, "unknown",
|
|
225
|
-
if (type === "string") return walkString(resolved,
|
|
226
|
-
if (type === "number" || type === "integer") return walkNumber(resolved,
|
|
227
|
-
if (type === "boolean") return walkBoolean(resolved,
|
|
228
|
-
if (type === "null") return buildField(resolved, "null",
|
|
234
|
+
if (type === void 0) return buildField(resolved, "unknown", ctxWithRef);
|
|
235
|
+
if (type === "string") return walkString(resolved, ctxWithRef);
|
|
236
|
+
if (type === "number" || type === "integer") return walkNumber(resolved, ctxWithRef);
|
|
237
|
+
if (type === "boolean") return walkBoolean(resolved, ctxWithRef);
|
|
238
|
+
if (type === "null") return buildField(resolved, "null", ctxWithRef);
|
|
229
239
|
if (type === "object") {
|
|
230
240
|
const properties = getObject(resolved, "properties");
|
|
231
|
-
if (properties !== void 0) return walkObject(resolved, properties,
|
|
241
|
+
if (properties !== void 0) return walkObject(resolved, properties, ctxWithRef);
|
|
232
242
|
const additionalProps = getObject(resolved, "additionalProperties");
|
|
233
|
-
if (additionalProps !== void 0) return walkRecord(resolved, additionalProps,
|
|
234
|
-
return buildField(resolved, "object",
|
|
243
|
+
if (additionalProps !== void 0) return walkRecord(resolved, additionalProps, ctxWithRef);
|
|
244
|
+
return buildField(resolved, "object", ctxWithRef);
|
|
235
245
|
}
|
|
236
|
-
if (type === "array") return walkArray(resolved,
|
|
237
|
-
return buildField(resolved, "unknown",
|
|
246
|
+
if (type === "array") return walkArray(resolved, ctxWithRef);
|
|
247
|
+
return buildField(resolved, "unknown", ctxWithRef);
|
|
238
248
|
}
|
|
239
249
|
function walkString(schema, ctx) {
|
|
240
250
|
if (getString(schema, "format") === "binary") return buildField(schema, "file", ctx);
|