Skip to main content
The parser option customizes how your OpenAPI specification is parsed and transformed before plugins process it.

Overview

openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://api.example.com/openapi.json',
  output: './src/client',
  parser: {
    filters: {
      tags: {
        include: ['users', 'posts'],
      },
    },
    transforms: {
      enums: 'root',
    },
  },
});

Filters

Filters select a subset of your OpenAPI specification before it’s passed to plugins.
parser.filters.operations
object
Filter operations (endpoints) to include or exclude.
parser.filters.tags
object
Filter by OpenAPI tags.
parser.filters.schemas
object
Filter schema definitions to include or exclude.
parser.filters.parameters
object
Filter parameter definitions.
parser.filters.requestBodies
object
Filter request body definitions.
parser.filters.responses
object
Filter response definitions.
parser.filters.deprecated
boolean
default:true
Include deprecated resources in the output.Set to false to exclude all resources marked as deprecated in your OpenAPI specification.
parser: {
  filters: {
    deprecated: false,
  },
}
parser.filters.orphans
boolean
default:false
Keep reusable components without any references from operations in the output.By default, unreferenced schemas are excluded.
parser.filters.preserveOrder
boolean
default:false
Preserve key order when processing your input. Disabled by default for performance.

Transforms

Transforms modify or normalize the OpenAPI specification in standardized ways.
parser.transforms.enums
boolean | string | object
default:false
Control how enums are handled in your specification.Your input might contain two types of enums:
  • Root enums: Defined as reusable components
  • Inline enums: Nested within other schemas
Only root enums are typically exported by plugins. Use this transform to promote inline enums to root level.
parser: {
  transforms: {
    enums: true, // Enable with defaults (mode: 'root')
  },
}
parser.transforms.readWrite
boolean | object
default:true
Separate schemas for read (response) and write (request) operations.Schemas might contain read-only or write-only fields. This transform creates separate schemas to avoid asking users to provide read-only fields in requests or expecting write-only fields in responses.
parser: {
  transforms: {
    readWrite: {
      enabled: true,
      requests: '{{name}}Input',
      responses: '{{name}}Output',
    },
  },
}
parser.transforms.propertiesRequiredByDefault
boolean
default:false
Treat all object properties as required by default unless explicitly marked as optional.By default (per OpenAPI spec), missing required keyword means no properties are required. Some specifications expect the opposite behavior.
parser: {
  transforms: {
    propertiesRequiredByDefault: true,
  },
}
parser.transforms.schemaName
string | function
Rename schema component keys throughout the specification, automatically updating all $ref pointers.Useful when schema names are auto-generated or follow awkward naming conventions.
parser: {
  transforms: {
    schemaName: (name) => name.replace(/_v\d+_\d+_\d+_/, '_'),
  },
}

Pagination

parser.pagination.keywords
string[]
Array of keywords to identify pagination fields in schemas and parameters.These keywords help plugins detect paginated operations and generate appropriate code.
parser: {
  pagination: {
    keywords: ['page', 'pageSize', 'cursor', 'limit'],
  },
}

Validation

parser.validate_EXPERIMENTAL
boolean | string
default:false
Experimental: Validate the input OpenAPI specification before generating output.This is a lightweight, experimental feature with support added on an ad hoc basis.Options:
  • false — No validation
  • true or 'warn' — Validate and warn about issues
  • 'strict' — Validate and fail on any issues
parser: {
  validate_EXPERIMENTAL: 'warn',
}

Examples

Filter to Specific Tags

openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://api.example.com/openapi.json',
  output: './src/client',
  parser: {
    filters: {
      tags: {
        include: ['users', 'posts'],
      },
    },
  },
});

Exclude Deprecated Operations

openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://api.example.com/openapi.json',
  output: './src/client',
  parser: {
    filters: {
      deprecated: false,
    },
  },
});

Promote Inline Enums

openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://api.example.com/openapi.json',
  output: './src/client',
  parser: {
    transforms: {
      enums: {
        enabled: true,
        mode: 'root',
        case: 'SCREAMING_SNAKE_CASE',
        name: '{{name}}Enum',
      },
    },
  },
});

Custom Schema Naming

openapi-ts.config.ts
import { defineConfig } from '@hey-api/openapi-ts';

export default defineConfig({
  input: 'https://api.example.com/openapi.json',
  output: './src/client',
  parser: {
    transforms: {
      // Remove version suffixes from schema names
      schemaName: (name) => name.replace(/_v\d+$/, ''),
    },
  },
});

Build docs developers (and LLMs) love