adapter: adapterOas()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.
- Downloads806.2K/ monthnpm, last 30 days
- GitHub stars1.9Kkubb-labs/kubb
- Unpacked size1.0MBv5.21.2 on npm
- Latest release3h agov5.21.2 · Nov 22, 2026
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
inputURL and any remote$refwith 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-oasbun add -d @kubb/adapter-oaspnpm add -D @kubb/adapter-oasnpm install --save-dev @kubb/adapter-oasyarn add -D @kubb/adapter-oaskubb 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
| Option | Default | What it does |
|---|---|---|
validate | true | Checks 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. |
pathParamsCasing | None | 'camelcase' renames path parameters, such as {pet-id} to petId. |
server | None | Picks the servers entry that becomes the document baseURL. It does not change where a client sends requests. |
contentType | Every media type | Keeps 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()],
})// excerpt, without JSDoc
export type Order = {
id?: number // int64, `bigint` by default
petId?: number
quantity?: number // int32
shipDate?: Date // date-time, `string` by default
complete?: boolean
}Dependencies
No extension dependencies.
