chanfana (formerly itty-router-openapi) is a library that adds OpenAPI 3 and 3.1 schema generation and validation to any router, primarily targeting Hono and itty-router. Version 3.3.0, released by Cloudflare, emphasizes Cloudflare Workers but works on any runtime. Key differentiators: Zod v4 compatible with full TypeScript inference, class-based endpoints, CLI to extract schema, and extending existing apps without modifying old routes. Release cadence is active with frequent updates. Pairs with Hono, itty-router, and zod.
npm install chanfanaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up an OpenAPI endpoint using chanfana with Hono, Zod validation, and Cloudflare Workers bindings.
Use import syntax instead of require(). Ensure package.json has 'type': 'module' or use .mjs extension.
Replace 'itty-router-openapi' with 'chanfana' in package.json dependencies and all import statements.
Update Zod to v4 and adjust schema definitions (e.g., z.number().int() instead of z.number() for integer).
Call fromHono(app, options) immediately after creating the Hono app, before adding any routes.
Ensure handler returns a proper Response object (e.g., new Response(...)).
Ensure wrangler.toml is present and that the OpenAPI schema endpoint is registered (usually via fromHono).
Set 'type': 'module' in package.json or rename file to .mjs.
Use correct named import: import { OpenAPIRoute } from 'chanfana'.Ensure named import: import { fromHono } from 'chanfana'. Upgrade to v3+.Use z.coerce.number() or preprocess to parse string to number in schema.