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
According to the OpenAPI specification, the examples field in a response must be an object. However, when using Schema.openapi({ examples }), if examples is provided as an array, it is output as an array in the generated OpenAPI spec. This causes Swagger UI to fail to parse the examples correctly. Additionally, the examples provided in the schema are not displayed at all in Swagger UI.
Implementation
import{OpenAPIHono,createRoute,z}from"@hono/zod-openapi";constResourceOutputSchema=z.object({status: z.enum(["pending","completed"]),}).openapi({description: "The status of the resource",examples: [{status: "pending"},{status: "completed"}],});constapiDefinition=createRoute({method: "get",path: "/resource/:id",request: {params: z.object({id: z.string(),}),},responses: {200: {description: "Successful response",content: {"application/json": {schema: ResourceOutputSchema,},},},},});exportconstgetResourceRoute=(app: OpenAPIHono)=>{returnapp.openapi(apiDefinition,async(c)=>{returnc.json({status: "completed"asconst},200);});};
Summary
According to the OpenAPI specification, the
examples
field in a response must be an object. However, when usingSchema.openapi({ examples })
, ifexamples
is provided as an array, it is output as an array in the generated OpenAPI spec. This causes Swagger UI to fail to parse the examples correctly. Additionally, the examples provided in the schema are not displayed at all in Swagger UI.Implementation
Generated OpenAPI Spec
The examples provided in the schema are not displayed in Swagger UI:
Additional Notes
If my understanding is incorrect and examples being an array is intended behavior, I’d appreciate clarification. Thank you!
The text was updated successfully, but these errors were encountered: