Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions packages/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,12 @@ function formatZodType(schema: z.ZodType): string {
case "boolean":
return "boolean";
case "ZodLiteral":
case "literal":
return JSON.stringify(def.value);
case "literal": {
// Zod 4 uses def.values (array), Zod 3 uses def.value
const litValues = def.values as unknown[] | undefined;
const litValue = litValues?.[0] ?? def.value;
return JSON.stringify(litValue);
}
case "ZodEnum":
case "enum": {
// Zod 3 uses values array, Zod 4 uses entries object
Expand Down Expand Up @@ -1345,6 +1349,20 @@ function formatZodType(schema: z.ZodType): string {
? options.map((opt) => formatZodType(opt)).join(" | ")
: "unknown";
}
case "ZodRecord":
case "record": {
const keyType = (def.keyType as z.ZodType) ?? undefined;
const valueType =
(def.valueType as z.ZodType) ?? (def.element as z.ZodType) ?? undefined;
const keyStr = keyType ? formatZodType(keyType) : "string";
const valueStr = valueType ? formatZodType(valueType) : "unknown";
return `Record<${keyStr}, ${valueStr}>`;
}
case "ZodDefault":
case "default": {
const inner = (def.innerType as z.ZodType) ?? (def.wrapped as z.ZodType);
return inner ? formatZodType(inner) : "unknown";
}
default:
return "unknown";
}
Expand Down
22 changes: 20 additions & 2 deletions packages/yaml/src/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ function formatZodType(schema: ZodLike): string {
case "boolean":
return "boolean";
case "ZodLiteral":
case "literal":
return JSON.stringify(def.value);
case "literal": {
// Zod 4 uses def.values (array), Zod 3 uses def.value
const litValues = def.values as unknown[] | undefined;
const litValue = litValues?.[0] ?? def.value;
return JSON.stringify(litValue);
}
case "ZodEnum":
case "enum": {
let values: string[];
Expand Down Expand Up @@ -115,6 +119,20 @@ function formatZodType(schema: ZodLike): string {
? options.map((opt) => formatZodType(opt)).join(" | ")
: "unknown";
}
case "ZodRecord":
case "record": {
const keyType = (def.keyType as ZodLike) ?? undefined;
const valueType =
(def.valueType as ZodLike) ?? (def.element as ZodLike) ?? undefined;
const keyStr = keyType ? formatZodType(keyType) : "string";
const valueStr = valueType ? formatZodType(valueType) : "unknown";
return `Record<${keyStr}, ${valueStr}>`;
}
case "ZodDefault":
case "default": {
const inner = (def.innerType as ZodLike) ?? (def.wrapped as ZodLike);
return inner ? formatZodType(inner) : "unknown";
}
default:
return "unknown";
}
Expand Down