H
Hono•3mo ago
PaulRudin

Openapi query params

I'm experimenting with openapi docs. I have:
const paramsSchema = z.object({
entry_id: z.string().openapi({
param: {
name: "entry_id",
in: "path",
},
example: "42",
}),
event_id: z.string().openapi({
param: {
name: "event_id",
in: "path",
},
example: "99",
}),
fixtures_event_id: z.string().optional().openapi({
param: {
name: "fixtures_event_id",
in: "query",
}
})
});

const route = createRoute({
method: "get",
path: "/",
request: {
params: paramsSchema,
},
responses: {
200: {
content: {
"application/json": {
schema: PicksResponse,
},
},
description: "get the picks",
},
},
});
const paramsSchema = z.object({
entry_id: z.string().openapi({
param: {
name: "entry_id",
in: "path",
},
example: "42",
}),
event_id: z.string().openapi({
param: {
name: "event_id",
in: "path",
},
example: "99",
}),
fixtures_event_id: z.string().optional().openapi({
param: {
name: "fixtures_event_id",
in: "query",
}
})
});

const route = createRoute({
method: "get",
path: "/",
request: {
params: paramsSchema,
},
responses: {
200: {
content: {
"application/json": {
schema: PicksResponse,
},
},
description: "get the picks",
},
},
});
But this gives:
{"message":"Conflicting location for parameter fixtures_event_id","data":{"key":"in","values":["path","query"]}}
{"message":"Conflicting location for parameter fixtures_event_id","data":{"key":"in","values":["path","query"]}}
I'm not sure where it's getting the "path" bit for this query param?
1 Reply
PaulRudin
PaulRudinOP•3mo ago
It turns out that query params have to be nested under request.query, rather that request.params. It seems that the "in" bit it redundant in that case? But anyway - at least I have something that works now I would mark this as solved, but I can't see how to do it 🙂 ah, got it
Want results from more Discord servers?
Add your server