PaulRudin
Zod Openapi references
See e.g: https://github.com/samchungy/zod-openapi?tab=readme-ov-file#auto-registering-schema
If I do:
Then I get:
Am I missing something? How should I construct references?
import { z } from "@hono/zod-openapi";
const title = z.string().openapi({
description: 'Job title',
example: 'My job',
ref: 'jobTitle',
});
import { z } from "@hono/zod-openapi";
const title = z.string().openapi({
description: 'Job title',
example: 'My job',
ref: 'jobTitle',
});
src/schema/plfpl-schema.ts(28,26): error TS2769: No overload matches this call.
Overload 1 of 2, '(this: ZodString, metadata: Partial<ZodOpenAPIMetadata<string, string>>): ZodString', gave the following error.
Object literal may only specify known properties, and 'ref' does not exist in type 'Partial<ZodOpenAPIMetadata<string, string>>'.
Overload 2 of 2, '(this: ZodString, refId: string, metadata?: Partial<ZodOpenAPIMetadata<string, string>> | undefined): ZodString', gave the following error.
Argument of type '{ description: string; example: string; ref: string; }' is not assignable to parameter of type 'string'.
src/schema/plfpl-schema.ts(28,26): error TS2769: No overload matches this call.
Overload 1 of 2, '(this: ZodString, metadata: Partial<ZodOpenAPIMetadata<string, string>>): ZodString', gave the following error.
Object literal may only specify known properties, and 'ref' does not exist in type 'Partial<ZodOpenAPIMetadata<string, string>>'.
Overload 2 of 2, '(this: ZodString, refId: string, metadata?: Partial<ZodOpenAPIMetadata<string, string>> | undefined): ZodString', gave the following error.
Argument of type '{ description: string; example: string; ref: string; }' is not assignable to parameter of type 'string'.
2 replies
Openapi query params
I'm experimenting with openapi docs. I have:
But this gives:
I'm not sure where it's getting the "path" bit for this query param?
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",
},
},
});
{"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"]}}
4 replies