You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When working with the middleware and adding a catch handler to a route's description, I observed that the OpenAPI documentation fails to generate properly and results in a 500 Internal Server Error. Below is the relevant code snippet that causes the issue.
Steps to Reproduce
Use the @hono/zod-openapi library to define an API route.
Add a catch handler to the dialogs array schema in the request body, as shown in the code below.
Attempt to generate or interact with the OpenAPI documentation for the route.
Observe that the OpenAPI middleware fails with a 500 Internal Server Error.
// Working file with all my docexportconststoryStepRoute=createRoute({method: 'post',description: 'Create a new story step with dialogs',tags: ['StoryStep'],path: '/',security: [],request: {body: {content: {'multipart/form-data': {schema: z.object({title: z.string().max(255).min(2),image: FileRequestSchema,dialogs: z.array(z.object({title: z.string().max(255).min(2),content: z.string().max(10000).min(2),order: z.number().int().nonnegative(),})),}),},},},},responses: {
...protectedRouteResponse,
...authorizedResponse,500: {description: 'Internal Server Error',content: {'application/json': {schema: z.object({message: z.string(),}),},},},201: {description: 'Story step information',content: {'application/json': {schema: z.object({id: z.string(),title: z.string(),imageUrl: z.string(),dialogs: z.array(z.object({id: z.string(),title: z.string(),content: z.string(),order: z.number(),createdAt: z.date(),updatedAt: z.date(),})),createdAt: z.date(),updatedAt: z.date(),}),},},},},});
import{OpenAPIHono,createRoute}from'@hono/zod-openapi';import{FileRequestSchema}from'@/server/libs/openApi';exportconststoryStepRoute=createRoute({method: 'post',description: 'Create a new story step with dialogs',tags: ['StoryStep'],path: '/',security: [],request: {body: {content: {'multipart/form-data': {schema: z.object({title: z.string().max(255).min(2),image: FileRequestSchema,dialogs: z.array(z.object({title: z.string().max(255).min(2),content: z.string().max(10000).min(2),order: z.number().int().nonnegative(),})).catch(ctx=>{// This kill all the open api docif(typeofctx.input!=='string')thrownewError('Invalid input type');try{returnJSON.parse(ctx.input);}catch(error){thrownewError('Invalid JSON input');}}),}),},},},},responses: {500: {description: 'Internal Server Error',content: {'application/json': {schema: z.object({message: z.string(),}),},},},201: {description: 'Story step information',content: {'application/json': {schema: z.object({id: z.string(),title: z.string(),imageUrl: z.string(),dialogs: z.array(z.object({id: z.string(),title: z.string(),content: z.string(),order: z.number(),createdAt: z.date(),updatedAt: z.date(),})),createdAt: z.date(),updatedAt: z.date(),}),},},},},});
Observed Behavior
Adding the .catch() block to the dialogs array schema breaks the OpenAPI middleware functionality.
The documentation generation fails entirely.
The API server responds with a 500 Internal Server Error.
Expected Behavior
The .catch() block should not interfere with OpenAPI documentation generation.
The OpenAPI middleware should gracefully handle schemas with .catch() handlers or provide a meaningful error message to aid debugging.
Environment Details
Library Version: @hono/zod-openapi:0.16.0
Node.js Version: v20.14.0
Zod Version: 3.23.8
The text was updated successfully, but these errors were encountered:
Issue description
When working with the middleware and adding a catch handler to a route's description, I observed that the OpenAPI documentation fails to generate properly and results in a 500 Internal Server Error. Below is the relevant code snippet that causes the issue.
Steps to Reproduce
@hono/zod-openapi
library to define an API route.Observed Behavior
.catch()
block to thedialogs
array schema breaks the OpenAPI middleware functionality.500 Internal Server Error
.Expected Behavior
.catch()
block should not interfere with OpenAPI documentation generation..catch()
handlers or provide a meaningful error message to aid debugging.Environment Details
@hono/zod-openapi:0.16.0
The text was updated successfully, but these errors were encountered: