Repository navigation
Refactor to separate itty-router from openapi logic - #151
Conversation
|
🧪 A prerelease is available for testing 🧪 You can install this latest build in your project with: npm install --save https://prerelease-registry.devprod.cloudflare.dev/itty-router-openapi/runs/9555081565/npm-package-itty-router-openapi-151Or you can immediately run this with npx https://prerelease-registry.devprod.cloudflare.dev/itty-router-openapi/runs/9555081565/npm-package-itty-router-openapi-151 |
6eee299 to
6ea2011
Compare
|
That's great! |
dcafc96 to
bf31198
Compare
a8cc538 to
16ae377
Compare
16ae377 to
4711c09
Compare
7151dc9 to
e93663d
Compare
4cedb31 to
f3fd898
Compare
7ce627b to
9c23342
Compare
9c23342 to
dea759a
Compare
|
Awesome! I'll check the new stuff |
Project got renamed in early December to expand the supported libraries. cloudflare/chanfana#151
Project got renamed in early December to expand the supported libraries. cloudflare/chanfana#151
Project got renamed in early December to expand the supported libraries. cloudflare/chanfana#151
This refactors the OpenAPI logic and adds support for latest versions of itty-router and possibly other router (like hono)
The new version will require users to instantiate their own
itty-routerrouter like:Breaking changes:
OpenAPIRouter()methodaiPluginoptionskipValidationoption (see new validation method bellow)itty-routeris no longer a dependency and users must manually add it to their projectschemais no longer a static variableschema.parameterswas renamed toschema.requestto follow zod-to-openapi structurePathparameters are now calledparamsto match the validated Data object nameschema.requestBodywas renamed toschema.request.bodyto follow zod-to-openapi structurehandlefunction is called, developers must manually call thegetValidatedDatato execute the data validation steptry {} catch (e) {}to handle input errors, otherwise this library will return the errors in a Json response with http 400Additions:
await this.getValidatedData<typeof this.schema>()method to retrieve all validated data, when sending<typeof this.schema>in the generic the returned value will have full typescript inference based on the schemafromIttyRouter()instantiate methodfromHono()instantiate methodMigration guide:
npm install itty-router@latest --save)const router = OpenAPIRouter({...})const router = fromIttyRouter(Router(), {...})newfrom all "legacy type" call fromnew Str(...)intoStr(...)async handle(request: Request, env: Env, ctx: Context, data: any) {...}async handle(request: Request, env: Env, ctx: Context) {...}const data = await this.getValidatedData<typeof this.schema>()static schemato:schemaschema.parameters.queryintoschema.request.queryschema.parameters.pathintoschema.request.paramsschema.parameters.headersintoschema.request.headersz.object({...})schema.requestBodyintoschema.request.body: contentJson(z.object({...params.newModel}))Minimal Hono example