Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cloudflare/chanfana
OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://github.com/cloudflare/chanfana
api cloudflare cloudflare-workers hono honojs openapi openapi3 router swagger typescript workers workers-script
Last synced: 12 days ago
JSON representation
OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
- Host: GitHub
- URL: https://github.com/cloudflare/chanfana
- Owner: cloudflare
- License: mit
- Created: 2022-11-08T11:43:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-23T11:46:54.000Z (20 days ago)
- Last Synced: 2024-10-30T05:59:46.400Z (14 days ago)
- Topics: api, cloudflare, cloudflare-workers, hono, honojs, openapi, openapi3, router, swagger, typescript, workers, workers-script
- Language: TypeScript
- Homepage: https://chanfana.pages.dev
- Size: 1.74 MB
- Stars: 316
- Watchers: 10
- Forks: 41
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# chanfana
OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!---
**Documentation**: chanfana.pages.dev
**Source Code**: github.com/cloudflare/chanfana
---
[chanfana](https://github.com/cloudflare/chanfana) **(previously known as itty-router-openapi)** is a library that adds
OpenAPI schema generation and validation to any router (
Hono, itty-router, etc), meant to be a
powerful and lightweight
library for Cloudflare Workers but runs on any runtime supported by the base router.The key features are:
- OpenAPI 3 and 3.1 schema generator and validator
- Query, Path, Headers and Body typescript inference
- Fully written in typescript
- Class-based endpoints
- Extend existing Hono, itty-router, etc application, without touching old routes## Getting started
Get started with a template with this command:
```bash
npm create cloudflare@latest -- --type openapi
```## Installation
```bash
npm i chanfana --save
```## Minimal Hono Example
```ts
import { fromHono, OpenAPIRoute } from 'chanfana'
import { Hono } from 'hono'
import { z } from 'zod'export class GetPageNumber extends OpenAPIRoute {
schema = {
request: {
params: z.object({
id: z.string().min(2).max(10),
}),
query: z.object({
page: z.number().int().min(0).max(20),
}),
},
}async handle(c) {
const data = await this.getValidatedData()return c.json({
id: data.params.id,
page: data.query.page,
})
}
}// Star a Hono app
const app = new Hono()// Setup OpenAPI registry
const openapi = fromHono(app)// Register OpenAPI endpoints
openapi.get('/entry/:id', GetPageNumber)// Export the Hono app
export default app
```## Feedback and contributions
[chanfana](https://github.com/cloudflare/chanfana) aims to be at the core of new APIs built using
Workers and define a pattern to allow everyone to
have an OpenAPI-compliant schema without worrying about implementation details or reinventing the wheel.chanfana is considered stable and production ready and is being used with
the [Radar 2.0 public API](https://developers.cloudflare.com/radar/).Currently this package is maintained by the [Cloudflare Radar Team](https://radar.cloudflare.com/) and features are
prioritized based on the Radar roadmap.Nonetheless you can still open pull requests or issues in this repository and they will get reviewed.
You can also talk to us in the [Cloudflare Community](https://community.cloudflare.com/) or
the [Radar Discord Channel](https://discord.com/channels/595317990191398933/1035553707116478495)