Is it possible to use zodios to change the response type with Query parameter by parameter? #448
Answered
by
ecyrbe
soshiharami
asked this question in
Q&A
-
Is it possible to use zodios to change the response type with Query parameter by parameter? For example I want it to work like this export const endPoints = makeApi([
{
method: "get",
path: "/v1/test",
requestFormat: "json",
parameters: [
{
name: "id",
type: "Query",
schema: z.string(),
},
],
response: (()=> {
switch (id) {
case "A":
return TypeA;
case "B":
return TypeB;
default:
return TypeC;
}
})(),
},
]); |
Beta Was this translation helpful? Give feedback.
Answered by
ecyrbe
May 10, 2023
Replies: 1 comment 1 reply
-
Use zod discriminated unions or just unions. export const endPoints = makeApi([
{
method: "get",
path: "/v1/test?id=A",
requestFormat: "json",
response: TypeA ,
},
{
method: "get",
path: "/v1/test?id=B",
requestFormat: "json",
response: TypeB
},
]); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
soshiharami
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use zod discriminated unions or just unions.
And do a runtime check.
Else you can do this :