Skip to content

Issue with Dates and zod (loadVendor) #196

@jofflin

Description

@jofflin

Hi,
I automatically generate my schema for my endpoints. My issue: The types are dates and the toJsonSchema for zod v4 doesnt allow Dates (https://zod.dev/json-schema#unrepresentable)
There is a workaround to convert Dates to string date-time (https://zod.dev/json-schema#override) But i don't know understand on how to use the loadVendor correctly.
Currently my loadVendor looks like this:
loadVendor('zod', { toOpenAPISchema: (schema, context) => convertToOpenAPISchema( toJSONSchema(schema, { io: 'input', override: (ctx) => { const def = ctx.zodSchema._zod.def; logger.info('def', { def }); if (def.type === 'date') { ctx.jsonSchema.type = 'string'; ctx.jsonSchema.format = 'date-time'; } }, }) as Omit<ReturnType<typeof toJSONSchema>, 'exclusiveMaximum'> & { exclusiveMaximum?: number; }, context ), });

I also need to make the type casting because the JsonSchemas dont align.
Current versions:
zod 4.1.12
hono 4.9.8
hono-openapi 1.1.0

What I need:
Instructions on how to use loadVendor correctly (Do I need to inject is somewhere?)

Ideal solution:
A option for hono-openapi to automatically convert specific types to something else.
Something like
openAPIRouteHandler(app, { overrides: { date: (d) => {} } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions