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
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"react-virtualized-auto-sizer": "^1.0.20",
"react-window": "^1.8.10",
"stainless": "workspace:*",
"zod": "^3.22.4",
"zod": "^3.25.76",
"zustand": "^4.4.7"
},
"devDependencies": {
Expand Down
32 changes: 31 additions & 1 deletion packages/hono/src/honoPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,41 @@ describe("basic routing", () => {
"expected": "object",
"message": "Required",
"path": [
"<stainless request body>",
"<body>",
],
"received": "undefined",
},
],
"message": "Required at "<body>"",
}
`);
});

test("update posts, missing param", async () => {
const response = await app.request("/api/posts/5", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({}),
});
expect(response).toHaveProperty("status", 400);
expect(await response.json()).toMatchInlineSnapshot(`
{
"error": "bad request",
"issues": [
{
"code": "invalid_type",
"expected": "string",
"message": "Required",
"path": [
"<body>",
"content",
],
"received": "undefined",
},
],
"message": "Validation error: Required at "<body>.content"",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually might be nice to not have Validation error here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

}
`);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"lodash": "^4.17.21",
"stainless": "workspace:*",
"zod": "^3.22.4"
"zod": "^3.25.76"
},
"peerDependencies": {
"prisma": "^4.0.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/stainless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"lodash": "^4.17.21",
"qs": "^6.11.2",
"ts-node": "^10.9.1",
"zod": "^3.22.4",
"zod-openapi": "github:stainless-api/zod-openapi#2.8.0"
"zod": "^3.25.76",
"zod-openapi": "github:stainless-api/zod-openapi#2.8.0",
"zod-validation-error": "^4.0.1"
}
}
16 changes: 12 additions & 4 deletions packages/stainless/src/stl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as z from "./z";
import { openapiSpec } from "./openapiSpec";
import type { OpenAPIObject } from "zod-openapi/lib-types/openapi3-ts/dist/oas31";
import { fromZodError } from "zod-validation-error/v3";
import coerceParams from "./coerceParams";
export { openapiSpec };
export { type SelectTree, parseSelect } from "./parseSelect";
Expand Down Expand Up @@ -778,20 +779,27 @@ export class Stl<Plugins extends AnyPlugins> {
context.endpoint[coercedQuery] ??= coerceParams(context.endpoint.query);
context.parsedParams.query = await context.endpoint[coercedQuery]
.parseAsync(params.query, parseParams)
.catch(prependZodPath("<stainless request query>"));
.catch(prependZodPath("<query>"));
}
if (context.endpoint.path) {
context.endpoint[coercedPath] ??= coerceParams(context.endpoint.path);
context.parsedParams.path = await context.endpoint[coercedPath]
.parseAsync(params.path, parseParams)
.catch(prependZodPath("<stainless request path>"));
.catch(prependZodPath("<path>"));
}
context.parsedParams.body = await context.endpoint.body
?.parseAsync(params.body, parseParams)
.catch(prependZodPath("<stainless request body>"));
.catch(prependZodPath("<body>"));
} catch (error) {
if (error instanceof z.ZodError) {
throw new BadRequestError({ issues: error.issues });
let validationError = fromZodError(error).message;
if (validationError.startsWith("Validation error: ")) {
validationError = validationError.slice("Validation error: ".length);
}
throw new BadRequestError({
message: validationError,
issues: error.issues,
});
}
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-to-zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"lodash": "^4.17.21",
"pkg-up": "~3.1.0",
"ts-morph": "^19.0.0",
"zod": "^3.22.4"
"zod": "^3.25.76"
}
}
47 changes: 30 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.