Skip to content
OpenAPI

OpenAPI

Officialv5.8.3

@kubb/adapter-oas

kubb add adapter-oas

Options

Pass these options to adapterOas(). All of them are optional.

Options overview

OptionPurpose
validateValidate the spec before parsing.
contentTypePreferred media type for request and response schemas.
serverWhich spec server Kubb resolves into the document baseURL.
discriminatorHow discriminator fields are interpreted.
enumsWhere inline enums live.
dateTypeHow date-time, date, and time schemas are represented.
integerTypeHow integers map to TypeScript.
unknownTypeType for schemas Kubb cannot infer.
emptySchemaTypeType for empty schemas.
enumSuffixSuffix for derived enum names.

Option details

validate

Validates the OpenAPI spec with @readme/openapi-parser before parsing. Each problem is reported as a KUBB_INVALID_SPEC warning, and generation continues. Set it to false to skip the check, which makes generation faster on a large spec. Run kubb validate to list every error.

Typeboolean
Requiredfalse
Defaulttrue

contentType

Media type to keep when an operation declares several, for both request bodies and responses. Without a value, Kubb keeps every media type the operation declares.

Type'application/json' | string
Requiredfalse

server

Selects which entry in the spec's servers array Kubb resolves into the document baseURL, filling in any {variable} placeholders. server.index points at one of the spec's servers, usually 0 for the primary one. server.variables supplies placeholder values, falling back to each variable's default from the spec. Omit server and baseURL resolves to null.

Type{ index?: number, variables?: Record<string, string> }
Requiredfalse

The resolved baseURL reaches banner functions through BannerMeta.baseURL but does not set request URLs on its own. To change where a generated client sends requests, use that plugin's own baseURL option (@kubb/plugin-fetch, @kubb/plugin-axios, @kubb/plugin-msw).

With a spec server of https://api.{env}.example.com, server: { index: 0, variables: { env: 'prod' } } resolves baseURL to https://api.prod.example.com.

discriminator

How discriminator fields on oneOf/anyOf schemas are interpreted.

Type'preserve' | 'propagate'
Requiredfalse
Default'preserve'
'preserve'
Keeps child schemas exactly as written, though the discriminator still narrows types at the call site.
'propagate'
Pushes the discriminator property with its literal value into each child schema, so each branch's type field is precisely typed.
openapi: 3.0.3
components:
  schemas:
    Animal:
      required: [type]
      type: object
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'
      discriminator:
        propertyName: type
        mapping:
          cat: '#/components/schemas/Cat'
          dog: '#/components/schemas/Dog'
    Cat:
      type: object
      properties:
        type: { type: string }
        indoor: { type: boolean }
    Dog:
      type: object
      properties:
        type: { type: string }
        name: { type: string }

enums

Where inline enums live.

Type'inline' | 'root'
Requiredfalse
Default'inline'
'inline'
Keeps each enum on the property that declares it.
'root'
Lifts every inline enum to a reusable top-level schema named after its context (for example PetStatusEnum) and references it wherever it appears.

For an enum with values active and inactive on Pet.status:

export type Pet = { status?: 'active' | 'inactive' }

dateType

How date-time, date, and time schemas are represented downstream.

Typefalse | 'string' | 'stringOffset' | 'stringLocal' | 'date' | { dateTime?, date?, time? }
Requiredfalse
Default'string'

Pass a single value to apply it to all three formats:

false
Represents date and time values as plain strings without format validation.
'string'
Represents date-time, date, and time as ISO 8601 strings. The generated TypeScript type is string.
'stringOffset'
Represents date-time as a string with a timezone offset. The date and time formats fall back to 'string'.
'stringLocal'
Represents date-time as a local string without a timezone. The date and time formats fall back to 'string'.
'date'
Represents date and time values as JavaScript Date objects. JSON values need parsing to revive them as Date objects.

The string variants all emit string at the TypeScript type level. Schema plugins such as @kubb/plugin-zod validate the offset or local format.

Pass an object to set dateTime, date, and time independently. A key you leave out defaults to 'string', regardless of the other keys.

adapterOas({
  dateType: {
    dateTime: 'date', // Date object for timestamps
    date: 'string',
    time: 'string',
  },
})

integerType

How type: integer (and format: int64) maps to TypeScript.

Type'number' | 'bigint'
Requiredfalse
Default'bigint'
'bigint'
Represents 64-bit IDs exactly, but JSON.stringify and JSON.parse cannot round-trip it. Use it only when you handle bigint serialization yourself.
'number'
Fits most JSON APIs. It loses precision above Number.MAX_SAFE_INTEGER.

A schema with type: string stays a string whatever its format, so the ProtoJSON int64 strings that gRPC-gateway emits stay strings. @kubb/plugin-zod validates them with a digits regex, and @kubb/plugin-faker mocks them as numeric strings.

unknownType

AST type used when a schema's type cannot be inferred from the spec (additionalProperties: true, a missing type, and similar).

Type'any' | 'unknown' | 'void'
Requiredfalse
Default'unknown'
'unknown'
Requires callers to narrow the value before using it.
'any'
Allows callers to use the value without type checking.
'void'
Represents a value callers should not use. Choose it when matching a legacy API that uses void.

emptySchemaType

AST type used for empty schemas ({}). It takes the same values as unknownType and follows it unless you set it.

Type'any' | 'unknown' | 'void'
Requiredfalse
DefaultunknownType ('unknown' by default)
A common pairing sets unknownType: 'unknown' for safety and emptySchemaType: 'any' so empty 204 response bodies stay easy to use.

enumSuffix

Suffix for the names Kubb gives inline enums: schema name, property name, and suffix, in PascalCase. The status enum on Pet becomes PetStatusEnum, or PetStatusType with enumSuffix: 'type'.

Typestring
Requiredfalse
Default'enum'