Skip to content

Commit

Permalink
Merge branch 'cloudflare-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
troy-barnard committed Dec 12, 2024
2 parents 2eb0bc7 + 42256ee commit dad6b15
Show file tree
Hide file tree
Showing 50 changed files with 10,694 additions and 10,586 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
major:
update-types: [ "major" ]
prod-deps:
dependency-type: "production"
dev-deps:
dependency-type: "development"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,22 @@ jobs:
with:
name: npm-package-chanfana-${{ github.event.number }} # encode the PR number into the artifact name
path: chanfana-*.tgz

- name: 'Comment on PR with Link'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ github.event.number }}
message: |
🧪 A prerelease is available for testing 🧪
You can install this latest build in your project with:
```sh
npm install --save https://prerelease-registry.devprod.cloudflare.dev/chanfana/runs/${{ github.run_id }}/npm-package-chanfana-${{ github.event.number }}
```
Or you can immediately run this with `npx`:
```sh
npx https://prerelease-registry.devprod.cloudflare.dev/chanfana/runs/${{ github.run_id }}/npm-package-chanfana-${{ github.event.number }}
```
53 changes: 0 additions & 53 deletions .github/workflows/write-prerelease-comment.yml

This file was deleted.

20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# chanfana
<div align="center">
<a href="https://chanfana.pages.dev/">
<img src="https://raw.githubusercontent.com/cloudflare/chanfana/refs/heads/main/docs/images/logo.png" width="500" height="auto" alt="chanfana"/>
</a>
</div>


<p align="center">
<em>OpenAPI 3 and 3.1 schema generator and validator for <a href="https://github.com/honojs/hono" target="_blank">Hono</a>, <a href="https://github.com/kwhitley/itty-router" target="_blank">itty-router</a> and more!</em>
</p>

---
<hr />

**Documentation**: <a href="https://chanfana.pages.dev/">chanfana.pages.dev</a>

**Source Code**: <a href="https://github.com/cloudflare/chanfana/">github.com/cloudflare/chanfana</a>

---
<hr />

[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 (<a href="https://github.com/honojs/hono" target="_blank">
Expand All @@ -21,10 +26,10 @@ library for Cloudflare Workers but runs on any runtime supported by the base rou
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
- [Class-based endpoints](https://chanfana.pages.dev/user-guide/first-steps/)
- [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
- Extend existing [Hono](https://chanfana.pages.dev/routers/hono/), [itty-router](https://chanfana.pages.dev/routers/itty-router/), etc application, without touching old routes

## Getting started

Expand All @@ -48,6 +53,7 @@ import { Hono } from 'hono'
import { z } from 'zod'

export type Env = {
// Example bindings
DB: D1Database
BUCKET: R2Bucket
}
Expand Down Expand Up @@ -81,7 +87,7 @@ const app = new Hono()
// Setup OpenAPI registry
const openapi = fromHono(app)

// Register OpenAPI endpoints
// Register OpenAPI endpoints (this will also register the routes in Hono)
openapi.get('/entry/:id', GetPageNumber)

// Export the Hono app
Expand Down
80 changes: 41 additions & 39 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["dist", "docs", "example"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "warn",
"noImplicitAnyLet": "warn"
},
"performance": {
"noAccumulatingSpread": "off"
},
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": ["dist", "docs", "example"]
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 120
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noBannedTypes": "off",
"noThisInStatic": "off"
},
"suspicious": {
"noExplicitAny": "off",
"noImplicitAnyLet": "off"
},
"performance": {
"noAccumulatingSpread": "off"
},
"style": {
"noParameterAssign": "warn"
"noParameterAssign": "off"
}
}
}
}
}
Binary file added docs/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ nav:
- user-guide/first-steps.md
- user-guide/path-parameters.md
- user-guide/query-parameters.md
- user-guide/header-parameters.md
- user-guide/request-body.md
- user-guide/response-format.md
- user-guide/router-options.md
Expand All @@ -68,6 +69,7 @@ nav:
- advanced-user-guide/hiding-routes-in-openapi-schema.md
- advanced-user-guide/openapi-schema-customizations.md
- advanced-user-guide/streaming-responses.md
- advanced-user-guide/utilities.md
markdown_extensions:
- toc:
permalink: true
Expand Down
22 changes: 22 additions & 0 deletions docs/pages/advanced-user-guide/utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Accessing url parameters from the class schema

You can now get a list of url parameters inside the getSchema function.
This can be very helpful when auto generating schemas

```ts
import { OpenAPIRoute } from './route'

// Define route
router.get("/v1/:account_id/gateways/:gateway_id", GetGateway);

export class GetAccountStats extends OpenAPIRoute {
getSchema() {
console.log(this.params.urlParams)

// The line above will print this: ["account_id", "gateway_id"]
// You can use this to manipulate the schema, adding or removing fields

return this.schema
}
};
```
Loading

0 comments on commit dad6b15

Please sign in to comment.