Skip to content

Commit 23f41c7

Browse files
authored
test(v4): toJSONSchema - use validateOpenAPI30Schema in all relevant scenarios (#5163)
1 parent 3291c61 commit 23f41c7

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,10 @@ describe("toJSONSchema", () => {
580580
});
581581

582582
test("nullable openapi-3.0", () => {
583-
expect(z.toJSONSchema(z.string().nullable(), { target: "openapi-3.0" })).toMatchInlineSnapshot(`
583+
const schema = z.string().nullable();
584+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
585+
validateOpenAPI30Schema(jsonSchema);
586+
expect(jsonSchema).toMatchInlineSnapshot(`
584587
{
585588
"nullable": true,
586589
"type": "string",
@@ -590,7 +593,9 @@ describe("toJSONSchema", () => {
590593

591594
test("union with null openapi-3.0", () => {
592595
const schema = z.union([z.string(), z.null()]);
593-
expect(z.toJSONSchema(schema, { target: "openapi-3.0" })).toMatchInlineSnapshot(`
596+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
597+
validateOpenAPI30Schema(jsonSchema);
598+
expect(jsonSchema).toMatchInlineSnapshot(`
594599
{
595600
"anyOf": [
596601
{
@@ -610,7 +615,9 @@ describe("toJSONSchema", () => {
610615

611616
test("number with exclusive min-max openapi-3.0", () => {
612617
const schema = z.number().lt(100).gt(1);
613-
expect(z.toJSONSchema(schema, { target: "openapi-3.0" })).toMatchInlineSnapshot(`
618+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
619+
validateOpenAPI30Schema(jsonSchema);
620+
expect(jsonSchema).toMatchInlineSnapshot(`
614621
{
615622
"exclusiveMaximum": true,
616623
"exclusiveMinimum": true,
@@ -704,7 +711,9 @@ describe("toJSONSchema", () => {
704711

705712
test("record openapi-3.0", () => {
706713
const schema = z.record(z.string(), z.boolean());
707-
expect(z.toJSONSchema(schema, { target: "openapi-3.0" })).toMatchInlineSnapshot(`
714+
const jsonSchema = z.toJSONSchema(schema, { target: "openapi-3.0" });
715+
validateOpenAPI30Schema(jsonSchema);
716+
expect(jsonSchema).toMatchInlineSnapshot(`
708717
{
709718
"additionalProperties": {
710719
"type": "boolean",

0 commit comments

Comments
 (0)