diff --git a/README.md b/README.md index 7ac8132..8ac45db 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ export class GetPageNumber extends OpenAPIRoute { } } -// Star a Hono app +// Start a Hono app const app = new Hono() // Setup OpenAPI registry @@ -95,12 +95,7 @@ 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. +the [Radar 2.0 public API](https://developers.cloudflare.com/radar/) and many other Cloudflare products. 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) diff --git a/docs/pages/advanced-user-guide/custom-error-handling.md b/docs/pages/advanced-user-guide/custom-error-handling.md index f84d338..ae75243 100644 --- a/docs/pages/advanced-user-guide/custom-error-handling.md +++ b/docs/pages/advanced-user-guide/custom-error-handling.md @@ -2,6 +2,7 @@ In order to customize the zod error formats, just overwrite the `handleValidatio ```ts import { OpenAPIRoute } from 'chanfana' +import { Context } from 'hono' export class ToDoList extends OpenAPIRoute { schema = { @@ -18,7 +19,7 @@ export class ToDoList extends OpenAPIRoute { }) } - async handle(request: Request, env: any, context: any) { + async handle(c: Context) { // ... } } @@ -48,13 +49,14 @@ Then, in your endpoint extend from the new class ```ts import { MyProjectRoute } from './route' +import { Context } from 'hono' export class ToDoList extends MyProjectRoute { schema = { // ... } - async handle(request: Request, env: any, context: any, data: any) { + async handle(c: Context) { // ... } } diff --git a/docs/pages/advanced-user-guide/custom-response-formats.md b/docs/pages/advanced-user-guide/custom-response-formats.md index 79e069e..5fe275a 100644 --- a/docs/pages/advanced-user-guide/custom-response-formats.md +++ b/docs/pages/advanced-user-guide/custom-response-formats.md @@ -2,6 +2,7 @@ ```ts import { OpenAPIRoute, Str } from 'chanfana' +import { Context } from 'hono' export class ToDoList extends OpenAPIRoute { schema = { @@ -18,7 +19,7 @@ export class ToDoList extends OpenAPIRoute { }, } - async handle(request: Request, env: any, context: any) { + async handle(c: Context) { // ... } } @@ -28,6 +29,7 @@ export class ToDoList extends OpenAPIRoute { ```ts import { OpenAPIRoute, Str } from 'chanfana' +import { Context } from 'hono' export class ToDoList extends OpenAPIRoute { schema = { @@ -49,7 +51,7 @@ export class ToDoList extends OpenAPIRoute { }, } - async handle(request: Request, env: any, context: any, data: any) { + async handle(c: Context) { // ... } } diff --git a/docs/pages/advanced-user-guide/custom-response-headers.md b/docs/pages/advanced-user-guide/custom-response-headers.md index 32e2c90..2ffd52c 100644 --- a/docs/pages/advanced-user-guide/custom-response-headers.md +++ b/docs/pages/advanced-user-guide/custom-response-headers.md @@ -2,6 +2,7 @@ ```ts import { OpenAPIRoute, Str } from 'chanfana' +import { Context } from 'hono' export class ToDoList extends OpenAPIRoute { schema = { @@ -27,7 +28,7 @@ export class ToDoList extends OpenAPIRoute { } - async handle(request: Request, env: any, context: any, data: any) { + async handle(c: Context) { // ... } } @@ -37,6 +38,7 @@ export class ToDoList extends OpenAPIRoute { ```ts import { OpenAPIRoute, Str } from 'chanfana' +import { Context } from 'hono' export class ToDoList extends OpenAPIRoute { schema = { @@ -61,7 +63,7 @@ export class ToDoList extends OpenAPIRoute { } - async handle(request: Request, env: any, context: any, data: any) { + async handle(c: Context) { // ... } } diff --git a/docs/pages/advanced-user-guide/streaming-responses.md b/docs/pages/advanced-user-guide/streaming-responses.md index 89ee52f..67b0254 100644 --- a/docs/pages/advanced-user-guide/streaming-responses.md +++ b/docs/pages/advanced-user-guide/streaming-responses.md @@ -7,8 +7,9 @@ as soon as the they get generated by the model, instead of waiting for the compl ```ts import { OpenAPIRoute, OpenAPIRouter } from 'chanfana' -import {z} from 'zod' +import { z } from 'zod' import OpenAI from 'openai' +import { Context } from 'hono' export class ChatGPT extends OpenAPIRoute { schema = { @@ -23,12 +24,7 @@ export class ChatGPT extends OpenAPIRoute { }, } - async handle( - request: Request, - env: any, - context: any, - data: any - ) { + async handle(c: Context) { const { question } = data.query const { readable, writable } = new TransformStream() diff --git a/docs/pages/index.md b/docs/pages/index.md index 30f5865..8ac45db 100644 --- a/docs/pages/index.md +++ b/docs/pages/index.md @@ -95,12 +95,7 @@ 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. +the [Radar 2.0 public API](https://developers.cloudflare.com/radar/) and many other Cloudflare products. 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) diff --git a/docs/pages/type-hint.md b/docs/pages/type-hint.md index d4ef4a7..52de58f 100644 --- a/docs/pages/type-hint.md +++ b/docs/pages/type-hint.md @@ -58,6 +58,7 @@ To enable this, simply pass your endpoint schema to the generic type when retrie ```ts hl_lines="17" import { OpenAPIRoute, Str } from 'chanfana' +import { Context } from 'hono' export class TaskFetch extends OpenAPIRoute { schema = { @@ -68,7 +69,7 @@ export class TaskFetch extends OpenAPIRoute { }, } - async handle(request: Request, env: any, context: any) { + async handle(c: Context) { const data = await this.getValidatedData() // you now get type hints, when accessing the data argument diff --git a/docs/pages/types.md b/docs/pages/types.md index 9e7890d..8b2be02 100644 --- a/docs/pages/types.md +++ b/docs/pages/types.md @@ -36,6 +36,7 @@ Then use it in a endpoint like this: ```ts import { OpenAPIRoute } from 'chanfana' +import { Context } from 'hono' export class Example extends OpenAPIRoute { schema = { @@ -46,8 +47,9 @@ export class Example extends OpenAPIRoute { } } - async handle(request: Request, env: any, context: any) { - // TODO data + async handle(c: Context) { + const data = await this.getValidatedData() + return { validatedLimit: data.query.limit } @@ -95,6 +97,7 @@ in every place you could use a Zod types, like this: ```ts import { Str, Int, OpenAPIRoute } from 'chanfana' +import { Context } from 'hono' const queryDescription = Str({description: 'a valid email address'}) @@ -107,8 +110,9 @@ export class Example extends OpenAPIRoute { } } - async handle(request: Request, env: any, context: any) { - // todo data + async handle(c: Context) { + const data = await this.getValidatedData() + return { validatedDescription: data.query.description } diff --git a/docs/pages/user-guide/path-parameters.md b/docs/pages/user-guide/path-parameters.md index 8307e56..01c5ece 100644 --- a/docs/pages/user-guide/path-parameters.md +++ b/docs/pages/user-guide/path-parameters.md @@ -5,9 +5,10 @@ You can declare `params` parameters in the `request` property of your endpoint s The validated data is available under `data.params.`. -```ts hl_lines="9-11" +```ts hl_lines="10-12" import { OpenAPIRoute } from 'chanfana' -import {z} from 'zod' +import { z } from 'zod' +import { Context } from 'hono' export class ToDoFetch extends OpenAPIRoute { schema = { @@ -20,11 +21,7 @@ export class ToDoFetch extends OpenAPIRoute { } } - async handle( - request: Request, - env: any, - context: any, - ) { + async handle(c: Context) { const data = await this.getValidatedData() // You get full type inference when accessing the data variable diff --git a/docs/pages/user-guide/query-parameters.md b/docs/pages/user-guide/query-parameters.md index 98b8277..0482a9d 100644 --- a/docs/pages/user-guide/query-parameters.md +++ b/docs/pages/user-guide/query-parameters.md @@ -5,9 +5,10 @@ You can declare `query` parameters in the `request` property of your endpoint sc The validated data is available under `data.query.`. -```ts hl_lines="9-11" +```ts hl_lines="10-12" import { OpenAPIRoute } from 'chanfana' -import {z} from 'zod' +import { z } from 'zod' +import { Context } from 'hono' export class ToDoFetch extends OpenAPIRoute { schema = { @@ -20,11 +21,7 @@ export class ToDoFetch extends OpenAPIRoute { } } - async handle( - request: Request, - env: any, - context: any, - ) { + async handle(c: Context) { const data = await this.getValidatedData() // You get full type inference when accessing the data variable diff --git a/docs/pages/user-guide/request-body.md b/docs/pages/user-guide/request-body.md index 7f0a370..92325de 100644 --- a/docs/pages/user-guide/request-body.md +++ b/docs/pages/user-guide/request-body.md @@ -9,9 +9,10 @@ For nested objects the validated data will be under the same position as defined In this example, the description can be either a string or an array of strings. -```ts hl_lines="7-11" +```ts hl_lines="10-25" import { OpenAPIRoute, Str, Enumeration } from 'chanfana' import { z } from 'zod' +import { Context } from 'hono' export class ToDoCreate extends OpenAPIRoute { schema = { @@ -37,11 +38,7 @@ export class ToDoCreate extends OpenAPIRoute { }, } - async handle( - request: Request, - env: any, - context: any, - ) { + async handle(c: Context) { const data = await this.getValidatedData() const newToDo = data.body @@ -63,9 +60,10 @@ Notice that when using `legacyTypeIntoZod` typescript inference is not available Here's an example of a response schema using variables -```ts +```ts hl_lines="10-19" import { OpenAPIRoute, legacyTypeIntoZod } from 'chanfana' import { z } from 'zod' +import { Context } from 'hono' export class ToDoCreate extends OpenAPIRoute { schema = { @@ -85,11 +83,7 @@ export class ToDoCreate extends OpenAPIRoute { }, } - async handle( - request: Request, - env: any, - context: any, - ) { + async handle(c: Context) { const data = await this.getValidatedData() const newToDo = data.body @@ -105,9 +99,10 @@ under the hood, for you to have even more flexibility. Notice that when using `contentJson` typescript inference is not available! -```ts +```ts hl_lines="10-13" import { contentJson, OpenAPIRoute } from 'chanfana' import { z } from 'zod' +import { Context } from 'hono' export class ToDoCreate extends OpenAPIRoute { schema = { @@ -121,11 +116,7 @@ export class ToDoCreate extends OpenAPIRoute { } } - async handle( - request: Request, - env: any, - context: any, - ) { + async handle(c: Context) { const data = await this.getValidatedData() const newToDo = data.body diff --git a/docs/pages/user-guide/security.md b/docs/pages/user-guide/security.md index 18ff23b..fe4ce6a 100644 --- a/docs/pages/user-guide/security.md +++ b/docs/pages/user-guide/security.md @@ -32,7 +32,7 @@ endpoints. For this add the `security` component to your main `router` schema customization field Notice that the key used in security must be the same used to register the component -```ts hl_lines="5 13" +```ts hl_lines="6 14" const app = new Hono() const openapi = fromHono(app, { schema: { @@ -60,7 +60,7 @@ openapi.registry.registerComponent( For this add the `security` component to your main `endpoint` schema customization field Notice that the key used in security must be the same used to register the component -```ts hl_lines="14 26" +```ts hl_lines="16 29" export class ScanMetadataCreate extends OpenAPIRoute { schema = { tags: ['Scans'],