schema-components 1.12.0 → 1.12.2

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.
@@ -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 resolved = resolveRef(schema, ctx.rootDocument, /* @__PURE__ */ new Set());
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, ctx);
222
- if ("const" in resolved) return walkLiteral(resolved, ctx);
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", ctx);
225
- if (type === "string") return walkString(resolved, ctx);
226
- if (type === "number" || type === "integer") return walkNumber(resolved, ctx);
227
- if (type === "boolean") return walkBoolean(resolved, ctx);
228
- if (type === "null") return buildField(resolved, "null", ctx);
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, ctx);
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, ctx);
234
- return buildField(resolved, "object", ctx);
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, ctx);
237
- return buildField(resolved, "unknown", ctx);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "schema-components",
3
- "version": "1.12.0",
3
+ "version": "1.12.2",
4
4
  "description": "React components that render UI from Zod schemas, JSON Schema, and OpenAPI documents",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",