OpenAPI

Overview

npm i @webroute/route

@webroute/oas provides utilities for building and consuming OpenAPI specs.

All @webroute/oas functionality leverages the fantastic work by the openapi3-ts package.

Server-side

When creating our APIs, we add metadata to our schema, which is then interpreted by createSpec, to enrich our OpenAPI specs without any awkward APIs.

const DecoratedSchema = OAS.Schema(UserSchema, {
  id: "User",
  description: "A public user object",
});

Read more about decorators.

Inference

@webroute/oas enables directly parsing an OpenAPI spec into useful typescript types, without any code generation.

import spec from "openapi-spec.json";
 
type AppSpec = ParseSpec<typeof spec>;

This is primarily useful for generating typed clients, but can also be used to define backends up-front and implementing the routes thereafter.

Read more about type inference.

On this page