tbeseda
Types issue in zod-openapi in recent release 0.19.4 (repro attached)
Maybe I'm holding it wrong, but this minimal file reproduces the type error:
import {OpenAPIHono, createRoute, z} from '@hono/zod-openapi'
interface AppBindings { Variables: { userId: string } }
const route = createRoute({
method: 'get',
path: '/widget/{widgetId}',
request: {
params: z.object({ widgetId: z.string() }),
},
responses: {
200: {
content: {
'application/json': {
schema: z.object({ widgetId: z.string() }),
},
},
description: 'Success',
},
404: {
content: {
'application/json': {
schema: z.object({
error: z.object({
code: z.string(),
message: z.string(),
}),
}),
},
},
description: 'Not Found',
},
},
})
const app = new OpenAPIHono<AppBindings>()
app.openapi(route, async (c) => { // <-- type error
const {widgetId} = c.req.valid('param')
const userId = c.get('userId')
if (widgetId === 'not-found') {
return c.json(
{
error: {
code: 'NOT_FOUND',
message: 'Not found',
},
},
404,
)
}
return c.json({widgetId}, 200)
})
import {OpenAPIHono, createRoute, z} from '@hono/zod-openapi'
interface AppBindings { Variables: { userId: string } }
const route = createRoute({
method: 'get',
path: '/widget/{widgetId}',
request: {
params: z.object({ widgetId: z.string() }),
},
responses: {
200: {
content: {
'application/json': {
schema: z.object({ widgetId: z.string() }),
},
},
description: 'Success',
},
404: {
content: {
'application/json': {
schema: z.object({
error: z.object({
code: z.string(),
message: z.string(),
}),
}),
},
},
description: 'Not Found',
},
},
})
const app = new OpenAPIHono<AppBindings>()
app.openapi(route, async (c) => { // <-- type error
const {widgetId} = c.req.valid('param')
const userId = c.get('userId')
if (widgetId === 'not-found') {
return c.json(
{
error: {
code: 'NOT_FOUND',
message: 'Not found',
},
},
404,
)
}
return c.json({widgetId}, 200)
})
10 replies