-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple content types in response and defining headers
- Loading branch information
Showing
5 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Describing response headers: | ||
|
||
```ts | ||
import { OpenAPIRoute, Str } from '@cloudflare/itty-router-openapi' | ||
|
||
export class ToDoList extends OpenAPIRoute { | ||
static schema: OpenAPIRouteSchema = { | ||
responses: { | ||
200: { | ||
description: 'Object with user data.', | ||
schema: { | ||
series: { | ||
timestamps: ['2023-01-01 00:00:00'], | ||
values: [0.56], | ||
}, | ||
}, | ||
headers: { | ||
'x-bar': 'header-example', | ||
'x-foo': new Str({required: false}), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
|
||
async handle(request: Request, env: any, context: any, data: any) { | ||
// ... | ||
} | ||
} | ||
``` | ||
|
||
## Describing response headers with zod: | ||
|
||
```ts | ||
import { OpenAPIRoute, Str } from '@cloudflare/itty-router-openapi' | ||
|
||
export class ToDoList extends OpenAPIRoute { | ||
static schema: OpenAPIRouteSchema = { | ||
responses: { | ||
200: { | ||
description: 'Object with user data.', | ||
schema: { | ||
series: { | ||
timestamps: ['2023-01-01 00:00:00'], | ||
values: [0.56], | ||
}, | ||
}, | ||
headers: z.object({ | ||
'x-bar': z.string() | ||
}), | ||
}, | ||
}, | ||
} | ||
|
||
|
||
async handle(request: Request, env: any, context: any, data: any) { | ||
// ... | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters