Is it possible to allow pass object schema to ParametersBuilder#addQueries, #addPaths, #addHeaders
?
#414
Replies: 1 comment 1 reply
-
It could but i decided not. Let me explain why. // io-ts validation
const jsonplaceholderApi = makeApi([
{
method: "get",
path: "/users",
alias: "getUsers",
description: "Get all users",
parameters: [
{
name: "q",
description: "full text search",
type: "Query",
schema: t.string,
},
{
name: "page",
description: "page number",
type: "Query",
schema: t.union([t.number, t.undefined]),
},
],
response: usersSchema,
},
{
method: "get",
path: "/users/:id",
description: "Get a user",
response: userSchema,
},
]); or with typescript schemas : // no runtime validation, on ts compile time definition
const jsonplaceholderApi = makeApi([
{
method: "get",
path: "/users",
description: "Get all users",
parameters: [
{
name: "q",
description: "full text search",
type: "Query",
schema: tsSchema<string>(),
},
{
name: "page",
description: "page number",
type: "Query",
schema: tsSchema<number | undefined>(),
},
],
response: usersSchema,
},
{
method: "get",
path: "/users/:id",
description: "Get a user",
response: userSchema,
},
]); So while it's technically possible to do that for zod only, since zodios v11 will be agnostic to validation library, i decided to not add this feature to parameterBuilder. However, you can still have an implementation at user level code, see here an exemple on how to do that : https://twitter.com/ecyrbedev/status/1642511317943631875 |
Beta Was this translation helpful? Give feedback.
-
I also want to expose schema and type for parameters, it would be nice we pass pass a object schema to the builder.
for example
Beta Was this translation helpful? Give feedback.
All reactions