Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7f5a76f

Browse filesBrowse files
authored
Use output type for preprocess (#4553)
1 parent 182dc49 commit 7f5a76f
Copy full SHA for 7f5a76f

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/zod/src/v4/classic/tests/to-json-schema.test.ts
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,3 +1943,14 @@ test("examples on pipe", () => {
19431943
// `);
19441944

19451945
// });
1946+
1947+
test("use output type for preprocess", () => {
1948+
const a = z.preprocess((val) => String(val), z.string());
1949+
1950+
expect(z.toJSONSchema(a, { io: "input" })).toMatchInlineSnapshot(`
1951+
{
1952+
"$schema": "https://json-schema.org/draft/2020-12/schema",
1953+
"type": "string",
1954+
}
1955+
`);
1956+
});
Collapse file

‎packages/zod/src/v4/core/to-json-schema.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/core/to-json-schema.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ export class JSONSchemaGenerator {
499499
break;
500500
}
501501
case "pipe": {
502-
const innerType = this.io === "input" ? def.in : def.out;
502+
const innerType = this.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
503503
this.process(innerType, params);
504504
result.ref = innerType;
505505
break;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.