H
Hono5mo ago
PaulRudin

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?
GitHub
GitHub - samchungy/zod-openapi: Use Zod Schemas to create OpenAPI v...
Use Zod Schemas to create OpenAPI v3.x documentation - samchungy/zod-openapi
1 Reply
PaulRudin
PaulRudinOP4mo ago
OK - I see that the hono integration changes the interface a little bit compared with zod-openapi

Did you find this page helpful?