PaulRudin
PaulRudin
HHono
Created by PaulRudin on 10/1/2024 in #help
Zod Openapi references
See e.g: https://github.com/samchungy/zod-openapi?tab=readme-ov-file#auto-registering-schema If I do:
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',
});
Then I get:
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'.
Am I missing something? How should I construct references?
2 replies
HHono
Created by PaulRudin on 9/27/2024 in #help
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?
4 replies