#itty-router-openapi

22 messages · Page 1 of 1 (latest)

keen heart
#

Hey there! I'm from the Radar team in Cloudflare, and we've just released an internal tool we built during Radar 2.0 development that adds OpenAPI schema generation and validation to the popular itty-router package
This new package is a drop-in replacement for existing applications that already use itty-router
Feel free to give feedback in this thread or in the #radar channel
https://github.com/cloudflare/itty-router-openapi

GitHub

OpenAPI 3 schema generator and validator for Cloudflare Workers - GitHub - cloudflare/itty-router-openapi: OpenAPI 3 schema generator and validator for Cloudflare Workers

craggy ibex
#

I spent the last two weeks mangling openapi-backend and dependencies in order to get them to work on Workers. This Friday, I got it to work... now this drops. Time for refactor!

spiral juniper
#

Nice!
Fwiw @keen heart, you can use /cfrole, and tap the option that shows up to log in with Access and get the orange role showing you're an employee 🙂

keen heart
#

Thanks @spiral juniper didn't know that 😃

remote edge
#

Totally biased, but I obviously love this! 🙂

near sequoia
#

Started using it last night and ❤️

remote edge
#

I still need to check this out! 🙂

keen heart
#

Hey there, I've published a new release yesterday with some neat features, including:

  • Support for raw strings, numbers and bools in response schemas
  • Support for nested routers
  • Support for disabling or modifying swagger ui, redoc and openapi url paths
    etc
near sequoia
#

Is there an example of a parameter that’s an array? Trying to figure it out

near sequoia
#

like guests: [ { name: "john" }, { name: "Jane" } ]

    parameters: {
      page: Query(Int, {
        description: 'Page number',
        default: 1,
        required: false,
      }),
      guests: ...
    },
keen heart
#

Hey @near sequoia it is not possible to get object arrays in the parameters field, you will have to move that into the requestBody

#

but if you really want to have that guests field in the url query, you will have to replace the object array with a string array like this guests: ["John", "Jane"]
and then define the parameter like this screenshot

near sequoia
#

thought the params where body params

near sequoia
#

@keen heart would you mind showing me an example of a array of items within the requestBody

keen heart
#

@near sequoia to define an array of items, you just need to wrap the item in [ ]

near gulch
#

@keen heart Hi! Is itty-router-openapi supposed to be compatible with itty-router middleware? I get TS type errors when trying to use my middleware with an OpenAPIRoute class instance.

For example:
router.get('/', () => console.log('my middleware'), DeviceList);

keen heart
#

Hey @near gulch it should be compatible, let me investigate the issue

keen heart
near gulch
#

@keen heart Ah yes I noticed everything worked as it should, it's just TS that is complaining. Ok will do. Thanks for checking!

cedar grove
#

Hi @keen heart I was checking this and was able to successfully built a dummy API but at same time I used hono and that also looks promising and the only difference I can understand (as of now, might be wrong) is that this^ let's you create openapi schema centric code and later you'll have /docs and /redocs but I was wondering what other differences are there?

near gulch
#

Hello. Grasping for straws here. Trying to migrate to itty-router-openapi 1.0 but the tests are failing. Every test that reference a module which includes 'itty-router-openapi' fails like this:


    Require stack:
      /home/daniel/projekt/xxxxxx/node_modules/@cloudflare/itty-router-openapi/node_modules/@asteasolutions/zod-to-openapi/dist/index.js
      /home/daniel/projekt/xxxxxx/node_modules/@cloudflare/itty-router-openapi/dist/index.js
      src/router/api/v1/device.ts
      src/router/api/v1/__tests__/device.spec.ts```

Using ts-jest.