Skip to content

Commit

Permalink
Fix headers validation for requests that receive empty headers
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Dec 7, 2024
1 parent a946ae5 commit a7001d9
Show file tree
Hide file tree
Showing 11 changed files with 210 additions and 69 deletions.
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.workflow_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.workflow_run.id }}/npm-package-chanfana-${{ github.event.number }}
```
53 changes: 0 additions & 53 deletions .github/workflows/write-prerelease-comment.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,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
- [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
- 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/)
- 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 Down
1 change: 1 addition & 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 Down
75 changes: 71 additions & 4 deletions docs/pages/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,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
- [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
- 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/)
- 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 Down
33 changes: 33 additions & 0 deletions docs/pages/user-guide/header-parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
**Please make sure to read the [Types](../types.md) page before continuing.**


You can declare `headers` parameters in the `request` property of your endpoint schema.

The validated data is available under `data.headers.<name>`.

```ts hl_lines="10-12"
import {OpenAPIRoute, Ip} from 'chanfana'
import {z} from 'zod'
import {Context} from 'hono'

export class ToDoFetch extends OpenAPIRoute {
schema = {
tags: ['ToDo'],
summary: 'Fetch a ToDo',
request: {
headers: z.object({
forwardedFor: Ip()
})
}
}

async handle(c: Context) {
const data = await this.getValidatedData<typeof this.schema>()

// You get full type inference when accessing the data variable
data.headers.forwardedFor

// ...
}
}
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
"umd",
"typed"
],
"author": "[email protected]",
"author": "Gabriel Massadas <[email protected]> (https://github.com/g4brym)",
"license": "MIT",
"homepage": "https://chanfana.pages.dev",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/cloudflare/chanfana.git"
"url": "https://github.com/cloudflare/chanfana.git"
},
"bugs": {
"url": "https://github.com/cloudflare/chanfana/issues"
Expand Down
Loading

0 comments on commit a7001d9

Please sign in to comment.