Skip to content

Commit 9443aab

Browse files
committed
Drop iso time in fromJSONSchema
1 parent decef9c commit 9443aab

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/zod/src/v4/classic/from-json-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ function convertSchema(schema: JSONSchema.JSONSchema | boolean, ctx: ConversionC
597597
}
598598
}
599599

600-
// Content keywords that should be captured as metadata
600+
// Content keywords - store as metadata
601601
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
602602
for (const key of contentMetadataKeys) {
603603
if (key in schema) {

packages/zod/src/v4/classic/tests/from-json-schema.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,3 +711,24 @@ test("$comment and $anchor are captured as metadata", () => {
711711
expect(meta?.$comment).toBe("This is a developer note");
712712
expect(meta?.$anchor).toBe("my-anchor");
713713
});
714+
715+
test("contentEncoding and contentMediaType are stored as metadata", () => {
716+
const customRegistry = z.registry<{ contentEncoding?: string; contentMediaType?: string }>();
717+
718+
const schema = fromJSONSchema(
719+
{
720+
type: "string",
721+
contentEncoding: "base64",
722+
contentMediaType: "image/png",
723+
},
724+
{ registry: customRegistry }
725+
);
726+
727+
// Should just be a string schema
728+
expect(schema.parse("aGVsbG8gd29ybGQ=")).toBe("aGVsbG8gd29ybGQ=");
729+
730+
// Content keywords should be in metadata
731+
const meta = customRegistry.get(schema);
732+
expect(meta?.contentEncoding).toBe("base64");
733+
expect(meta?.contentMediaType).toBe("image/png");
734+
});

0 commit comments

Comments
 (0)