Skip to content
Adapter
OpenAPI logo
adapter: adapterOas()
Officialv5.21.2kubb >=5.8.3node >=22.22

OpenAPI adapter

@kubb/adapter-oas

Reads an OpenAPI 2.0, 3.0, 3.1, or 3.2 spec and converts every schema and operation into the AST that Kubb plugins generate from.

kubb add adapter-oas
openapiswaggerapi-specparserconverter

The OpenAPI adapter reads an OpenAPI 2.0, 3.0, 3.1, or 3.2 spec and converts it into the AST that every plugin generates code from.

  • It is the first step of every build, so its options apply to all plugins.
  • It downloads a remote input URL and any remote $ref with a plain GET request, without credentials.
  • It reads the local files that external $refs point to, even outside the spec's folder, unless the host limits them, as a Kubb Studio agent does. See External refs. It never writes files.

Installation

kubb add adapter-oas

kubb add installs the version the Kubb registry pins and prints the adapter: adapterOas() line to add to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.

Setup

No setup is needed. defineConfig uses adapterOas() by default. Set adapter only to change its options.

Options worth knowing

OptionDefaultWhat it does
validatetrueChecks the spec and reports each problem as a warning. Turn it off to speed up a large spec.
dateType'string'Types date-time, date, and time as strings or as Date objects.
integerType'bigint'Types int64 and uint64 as bigint or number. Choose 'number' for most JSON APIs.
enums'inline''root' lifts inline enums to top-level schemas, such as PetStatusEnum.
discriminator'preserve''propagate' writes the discriminator value into each child schema.
pathParamsCasingNone'camelcase' renames path parameters, such as {pet-id} to petId.
serverNonePicks the servers entry that becomes the document baseURL. It does not change where a client sends requests.
contentTypeEvery media typeKeeps one media type when an operation declares several.

Run kubb validate to list every spec error.

Example

This config types dates as Date objects and 64-bit integers as numbers, so @kubb/plugin-ts writes this Order type:

import { defineConfig } from 'kubb/config'
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  adapter: adapterOas({ dateType: 'date', integerType: 'number' }),
  plugins: [pluginTs()],
})

Dependencies

No extension dependencies.