Migrating from itty router openapi
- install latest version
- install latest itty-router version (
npm install itty-router@latest --save
)
- replace your current router instance
- from:
const router = OpenAPIRouter({...})
- to:
const router = fromIttyRouter(Router(), {...})
- remove the
new
from all "legacy type" call from new Str(...)
into Str(...)
- remove the data argument from your endpoint's handle function
- from:
async handle(request: Request, env: Env, ctx: Context, data: any) {...}
- to:
async handle(request: Request, env: Env, ctx: Context) {...}
- add this variable to the first line of your endpoint handle function
const data = await this.getValidatedData<typeof this.schema>()
- remove the static keyword from the endpoints schema property from:
static schema
to: schema
- move query parameters from
schema.parameters.query
into schema.request.query
- move path parameters from
schema.parameters.path
into schema.request.params
- move headers parameters from
schema.parameters.headers
into schema.request.headers
- wrap your query, headers and params into a zod object
z.object({...})
- move you
schema.requestBody
into schema.request.body: contentJson(z.object({...params.newModel}))
- wrap all
schema.responses
into contentJson({...old_response_here}})