OpenAPI
routes
can join forces with @webroute/oas
to easily produce highly-customisable OpenAPI Specs (OAS).
By default, routes will automatically carry much useful information for OpenAPI. But to further enrich our APIs, we can use "decorators" from @webroute/oas
.
Leveraging @webroute/oas
Transform Routes
To build our OpenAPI spec itself, we can either manually format our routes to the correct shape for createSpec
. Alternatively, we can use the normaliseRoutes
function to assume the right shape.
Leveraging @webroute/schema
When building our spec we need to tell createSpec
how to handle our schema objects/functions. createSpec
accepts a formatter
argument responsible for converting validation schema -> JSON schema.
We can leverage a third-party converter, such as zod-to-json-schema
.
Or we could leverage @webroute/schema
.
Now we have a formatter
function which will convert zod
to typebox
(which is actually JSON schema).
Adding OpenAPI to routes is that easy.