跳到正文

chanfana

活跃
cloudflare/chanfana

为 Cloudflare Workers 上的 Hono、itty-router 等路由器提供 OpenAPI 3 和 3.1 Schema 生成与请求校验。

在 GitHub 查看
星标
767
Fork
71
关注
767
未关闭 Issue
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.

按共同分类和标签排序的同类开源项目。

全部 SDK 项目 →