Skip to content

chanfana

Active
cloudflare/chanfana

OpenAPI 3 and 3.1 schema generation and request validation for Hono, itty-router and other routers on Cloudflare Workers.

View on GitHub
Stars
767
Forks
71
Watchers
767
Open issues
55

Overview

chanfana (previously known as itty-router-openapi) adds OpenAPI 3 and 3.1 schema generation and request validation to existing routers such as Hono and itty-router. It is built as a lightweight library for Cloudflare Workers, but runs on any runtime the underlying router supports.

You define endpoints as classes with Zod schemas, and chanfana validates incoming requests, infers TypeScript types, and serves interactive API documentation automatically.

Key Features

  • OpenAPI 3 and 3.1 schema generation and validation
  • Zod v4 schemas with full TypeScript inference for query, path, headers, and body
  • Class-based endpoints that keep schema, validation, and handler together
  • Works with existing apps: wrap a Hono or itty-router app without touching old routes
  • Auto-generated interactive API docs served from your Worker
  • CLI (npx chanfana) that boots your Worker with wrangler dev and exports schema.json — handy in CI
  • AI coding skills to help assistants write chanfana endpoints

Getting Started

Scaffold a complete example — a Task API with Hono, D1, and Zod, including CRUD endpoints, tests, and docs at /api/docs:

npm create cloudflare@latest -- --template https://github.com/cloudflare/chanfana/tree/main/template

Or add it to an existing project:

npm i chanfana

Wrap your Hono app with fromHono(...), define endpoints by extending OpenAPIRoute with a Zod schema, and register them like normal routes. Requests that don’t match the schema are rejected with a clear validation error before your handler runs.

Use Cases

  • Typed, documented REST APIs on Cloudflare Workers
  • Adding OpenAPI docs to an existing Hono or itty-router project incrementally
  • Generating client SDKs from a schema exported in CI

License

MIT License.

Similar open-source projects, ranked by shared categories and tags.

All SDK projects →