openapi-zod-client
openapi-zod-client copied to clipboard
Path params are not using Schema Types
It seems these get inlined instead of using the shared schema type.
Current:
const endpoints = makeApi([
{
method: "get",
path: "/users/:id",
requestFormat: "json",
parameters: [
{
name: "id",
type: "Path",
schema: z.string().regex(/^user_[a-z0-9]{25,27}$/),
},
],
response: z.union([
z.object({ success: z.literal(true), item: User }),
z.object({
success: z.literal(false),
message: z.string().optional(),
issues: z.array(APIIssue).optional(),
}),
]),
errors: [
{
status: 400,
description: `Bad Request`,
schema: z.object({
success: z.literal(false),
message: z.string().optional(),
issues: z.array(APIIssue).optional(),
}),
},
],
},
]);
Expected:
const UserId = z.string().regex(/^user_[a-z0-9]{25,27}$/);
const User = z.object({
_id: UserId,
full_name: z.string().optional(),
email: z.string().optional(),
});
const endpoints = makeApi([
{
method: "get",
path: "/users/:id",
requestFormat: "json",
parameters: [
{
name: "id",
type: "Path",
schema: UserId,
},
],
response: z.union([
z.object({ success: z.literal(true), item: User }),
z.object({
success: z.literal(false),
message: z.string().optional(),
issues: z.array(APIIssue).optional(),
}),
]),
errors: [
{
status: 400,
description: `Bad Request`,
schema: z.object({
success: z.literal(false),
message: z.string().optional(),
issues: z.array(APIIssue).optional(),
}),
},
],
},
]);
Another bug found here is if you mess with the complexity threshold settings, you do get a separate schema called id
, and it overwrites each other, if you have another parameter with id and complexity.
hey, yeah pretty much the same issue as the other one (https://github.com/astahmer/openapi-zod-client/issues/158). how would you solve that ? feel free to make a PR if you come up with a good solution
i think this is also related to the problems i was experiencing around nullable. i think solving one would solve both. i have a PR with failing tests here, but no solution https://github.com/astahmer/openapi-zod-client/pull/177. just linking for completeness