{"id":13602164,"url":"https://github.com/cloudflare/chanfana","last_synced_at":"2025-05-14T13:06:06.270Z","repository":{"id":64264540,"uuid":"563328514","full_name":"cloudflare/chanfana","owner":"cloudflare","description":"OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!","archived":false,"fork":false,"pushed_at":"2025-03-31T09:01:58.000Z","size":4874,"stargazers_count":472,"open_issues_count":41,"forks_count":45,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-13T08:58:48.076Z","etag":null,"topics":["api","cloudflare","cloudflare-workers","hono","honojs","openapi","openapi3","router","swagger","typescript","workers","workers-script"],"latest_commit_sha":null,"homepage":"https://chanfana.pages.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudflare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-11-08T11:43:41.000Z","updated_at":"2025-04-12T16:23:34.000Z","dependencies_parsed_at":"2023-12-13T17:58:15.406Z","dependency_job_id":"a7d1581d-a673-47eb-b84e-8f16e83f300a","html_url":"https://github.com/cloudflare/chanfana","commit_stats":{"total_commits":202,"total_committers":26,"mean_commits":7.769230769230769,"dds":"0.33168316831683164","last_synced_commit":"2d353f41c8c88d03c0dbb86c8cd494d141181a2e"},"previous_names":["cloudflare/chanfana","cloudflare/itty-router-openapi"],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fchanfana","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fchanfana/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fchanfana/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudflare%2Fchanfana/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudflare","download_url":"https://codeload.github.com/cloudflare/chanfana/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149948,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cloudflare","cloudflare-workers","hono","honojs","openapi","openapi3","router","swagger","typescript","workers","workers-script"],"created_at":"2024-08-01T18:01:15.559Z","updated_at":"2025-05-14T13:06:06.211Z","avatar_url":"https://github.com/cloudflare.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","Frameworks \u0026 Libraries","api"],"sub_categories":["Utilities \u0026 Processing"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://chanfana.pages.dev/\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/cloudflare/chanfana/refs/heads/main/docs/images/logo.png\" width=\"500\" height=\"auto\" alt=\"chanfana\"/\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\n\u003cp align=\"center\"\u003e\n    \u003cem\u003eOpenAPI 3 and 3.1 schema generator and validator for \u003ca href=\"https://github.com/honojs/hono\" target=\"_blank\"\u003eHono\u003c/a\u003e, \u003ca href=\"https://github.com/kwhitley/itty-router\" target=\"_blank\"\u003eitty-router\u003c/a\u003e and more!\u003c/em\u003e\n\u003c/p\u003e\n\n\u003chr /\u003e\n\n**Documentation**: \u003ca href=\"https://chanfana.pages.dev/\"\u003echanfana.pages.dev\u003c/a\u003e\n\n**Source Code**: \u003ca href=\"https://github.com/cloudflare/chanfana/\"\u003egithub.com/cloudflare/chanfana\u003c/a\u003e\n\n\u003chr /\u003e\n\n[chanfana](https://github.com/cloudflare/chanfana) **(previously known as itty-router-openapi)** is a library that adds\nOpenAPI schema generation and validation to any router (\u003ca href=\"https://github.com/honojs/hono\" target=\"_blank\"\u003e\nHono\u003c/a\u003e, \u003ca href=\"https://github.com/kwhitley/itty-router\" target=\"_blank\"\u003eitty-router\u003c/a\u003e, etc), meant to be a\npowerful and lightweight\nlibrary for Cloudflare Workers but runs on any runtime supported by the base router.\n\nThe key features are:\n\n- OpenAPI 3 and 3.1 schema generator and validator\n- Fully written in typescript\n- [Class-based endpoints](https://chanfana.pages.dev/user-guide/first-steps/)\n- [Query](https://chanfana.pages.dev/user-guide/query-parameters/), [Path](https://chanfana.pages.dev/user-guide/path-parameters/), [Headers](https://chanfana.pages.dev/user-guide/header-parameters/) and [Body](https://chanfana.pages.dev/user-guide/request-body/) typescript inference\n- Extend existing [Hono](https://chanfana.pages.dev/routers/hono/), [itty-router](https://chanfana.pages.dev/routers/itty-router/), etc application, without touching old routes\n\n## Getting started\n\nGet started with a template with this command:\n\n```bash\nnpm create cloudflare@latest -- --type openapi\n```\n\n## Installation\n\n```bash\nnpm i chanfana --save\n```\n\n## Minimal Hono Example\n\n```ts\nimport { fromHono, OpenAPIRoute } from 'chanfana'\nimport { Hono } from 'hono'\nimport { z } from 'zod'\n\nexport type Env = {\n    // Example bindings\n    DB: D1Database\n    BUCKET: R2Bucket\n}\nexport type AppContext = Context\u003c{ Bindings: Env }\u003e\n\nexport class GetPageNumber extends OpenAPIRoute {\n  schema = {\n    request: {\n      params: z.object({\n        id: z.string().min(2).max(10),\n      }),\n      query: z.object({\n        page: z.number().int().min(0).max(20),\n      }),\n    },\n  }\n\n  async handle(c: AppContext) {\n    const data = await this.getValidatedData\u003ctypeof this.schema\u003e()\n\n    return c.json({\n      id: data.params.id,\n      page: data.query.page,\n    })\n  }\n}\n\n// Start a Hono app\nconst app = new Hono\u003c{ Bindings: Env }\u003e()\n\n// Setup OpenAPI registry\nconst openapi = fromHono(app)\n\n// Register OpenAPI endpoints (this will also register the routes in Hono)\nopenapi.get('/entry/:id', GetPageNumber)\n\n// Export the Hono app\nexport default app\n```\n\n## Feedback and contributions\n\n[chanfana](https://github.com/cloudflare/chanfana) aims to be at the core of new APIs built using\nWorkers and define a pattern to allow everyone to\nhave an OpenAPI-compliant schema without worrying about implementation details or reinventing the wheel.\n\nchanfana is considered stable and production ready and is being used with\nthe [Radar 2.0 public API](https://developers.cloudflare.com/radar/) and many other Cloudflare products.\n\nYou can also talk to us in the [Cloudflare Community](https://community.cloudflare.com/) or\nthe [Radar Discord Channel](https://discord.com/channels/595317990191398933/1035553707116478495)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fchanfana","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudflare%2Fchanfana","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudflare%2Fchanfana/lists"}