Skip to content
Reference

Options

Configuration options for @kubb/adapter-oas covering spec validation, content type, the server base URL, discriminators, enums, and how OpenAPI types map to TypeScript.

All adapterOas options are optional. Types and defaults are listed below.

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.
↳ server.indexSelect an entry in the spec's servers array.
↳ server.variablesSupply values for server URL variables.
discriminatorHow discriminator fields are interpreted.
enumsWhere inline enums live.
dateTypeHow date-time, date, and time schemas are represented.
↳ dateType.dateTimeConfigure the representation of timestamps.
↳ dateType.dateConfigure the representation of date-only values.
↳ dateType.timeConfigure the representation of time-only values.
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

Preferred media type when an operation defines several. Without a value, Kubb falls back to the first JSON-like media type in the spec (application/json, application/x-json, text/json, text/x-json, or any *+json), and to the first media type overall when none is JSON-like.

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'
Default value. 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'
Default value. 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'
Default value. 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. The offset and local distinction surfaces in schema output such as Zod.

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', // plain string for date-only values, since Date can't represent them safely
    time: 'string',
  },
})

integerType

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

Type'number' | 'bigint'
Requiredfalse
Default'bigint'
'bigint'
Default value. 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.

This option only applies to schemas that declare a numeric type. A schema that declares type: string stays a string whatever its format, so the { type: 'string', format: 'int64' } that gRPC-gateway and other ProtoJSON producers emit generates a string. @kubb/plugin-zod validates those fields with a digits .regex(...) and @kubb/plugin-faker mocks them with a numeric string.

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 fully empty schemas ({}). It follows unknownType unless you set it. Override it only when empty schemas should be treated differently from unresolvable ones.

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

enumSuffix

Suffix appended to derived enum names when Kubb has to invent one, typically for inline enums on object properties. The derived name joins the parent schema name, the property name, and the suffix in PascalCase, so an inline enum on the status property of the Pet schema derives PetStatusEnum. Set it to 'type' and the same enum derives PetStatusType.

Typestring
Requiredfalse
Default'enum'