Skip to content

Commit 76980c0

Browse files
committed
test: fix tests
1 parent d887807 commit 76980c0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/core/body.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe("resolveRequestBody", () => {
2626
},
2727
required: ["name"],
2828
additionalProperties: false,
29+
$schema: "https://json-schema.org/draft/2020-12/schema",
2930
},
3031
},
3132
},
@@ -49,10 +50,12 @@ describe("resolveRequestBody", () => {
4950
file: {
5051
type: "string",
5152
format: "binary",
53+
contentEncoding: "binary",
5254
},
5355
},
5456
required: ["file"],
5557
additionalProperties: false,
58+
$schema: "https://json-schema.org/draft/2020-12/schema",
5659
},
5760
},
5861
},
@@ -97,7 +100,8 @@ describe("parseRequestBody", () => {
97100
expect.objectContaining({
98101
code: "invalid_type",
99102
expected: "number",
100-
received: "undefined",
103+
message: "Invalid input: expected number, received undefined",
104+
path: ["age"],
101105
}),
102106
]));
103107

@@ -130,7 +134,8 @@ describe("parseRequestBody", () => {
130134
expect.objectContaining({
131135
code: "invalid_type",
132136
expected: "number",
133-
received: "undefined",
137+
message: "Invalid input: expected number, received undefined",
138+
path: ["age"],
134139
}),
135140
]));
136141
consoleSpy.mockRestore();

src/core/content.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ describe("resolveContent", () => {
4545
},
4646
required: ["name", "age"],
4747
additionalProperties: false,
48+
// @ts-expect-error: @omer-x/openapi-types doesn't have this
49+
$schema: "https://json-schema.org/draft/2020-12/schema",
4850
},
4951
},
5052
} satisfies RequestBodyObject["content"];

src/core/zod-error-handler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { convertStringToArray, convertStringToBoolean, convertStringToNumber } from "~/utils/type-conversion";
2-
import type { ZodType, ZodTypeDef } from "zod";
2+
import type { ZodType } from "zod";
33

4-
export function safeParse<I, O>(schema: ZodType<O, ZodTypeDef, I>, input: Record<string, unknown>) {
4+
export function safeParse<I, O>(schema: ZodType<O, I>, input: Record<string, unknown>) {
55
const result = schema.safeParse(input);
66
if (!result.success) {
77
for (const issue of result.error.issues) {
8-
if (issue.code === "invalid_type" && issue.received === "string") {
8+
const [key] = issue.path;
9+
if (issue.code === "invalid_type" && typeof key === "string" && key in input && typeof input[key] === "string") {
910
if (issue.expected === "number") {
1011
return safeParse(schema, convertStringToNumber(input, issue.path as string[]));
1112
}

0 commit comments

Comments
 (0)