openapi-to-typescript options
Every configuration option of @spartaficial/openapi-to-typescript: its type, its default and where it may be set. This page is generated from the generator's configuration schema, so it cannot drift from the code. For how the options combine, read the TypeScript generator guide; for where the options go, read Configuration files; for what the other generators accept, read Option parity.
Spec entry options
Each entry in specs accepts these options. The 2 required options come first, then the rest alphabetically. The "In defaults" column says whether the option may also be set once, under defaults, for every entry.
| Option | Type | Default | In defaults | Description |
|---|---|---|---|---|
input | string | required | no | Path to OpenAPI specification file (YAML or JSON) |
outputTypes | string | required | no | Output file path for generated types |
batchSize | number > 0 | 10 | yes | Batch size for parallel execution |
defaultNullable | boolean | false | yes | Treat all properties as nullable by default when not explicitly specified |
enumFormat | "enum" | "union" | "const-object" | "const-object" | yes | Format for generating enums |
fileHeader | string[] | — | yes | Custom comment lines to add at the very top of generated files |
ignoreHeaders | string[] | — | yes | Header parameter names to exclude from generated *HeaderParams types |
includeDescriptions | boolean | true | yes | Include JSDoc comments from schema descriptions |
name | string | — | no | A label for this specification entry |
operationFilters | object | — | yes | Filter which operations to include/exclude from generation (see the table below) |
prefix | string | — | yes | Prefix to add to all generated type/schema names |
refMappings | Record<string, string> | — | yes | Redirect remote $ref documents to local files, keyed by URL prefix |
schemaType | "all" | "request" | "response" | "all" | yes | Generate the request shape, the response shape, or everything |
showStats | boolean | true | yes | Show generation statistics in output file |
showWarnings | boolean | true | yes | Enable or disable warning messages during generation |
stripPathPrefix | string | — | yes | Strip a common prefix from all paths before generating operation-derived type names |
stripSchemaPrefix | string | string[] | — | yes | Strip a common prefix from all schema names before processing |
suffix | string | — | yes | Suffix to add to generated type/schema names |
useOperationId | boolean | true | yes | Whether to use operationId from OpenAPI spec for operation-derived naming |
operationFilters
Options of the operationFilters object. These are the operation filters every generator shares.
| Option | Type | Default | Description |
|---|---|---|---|
excludeDeprecated | boolean | false | Exclude operations marked as deprecated |
excludeMethods | string[] | — | Exclude operations with one of these HTTP methods |
excludeOperationIds | string[] | — | Exclude operations whose operationId matches one of these patterns |
excludePaths | string[] | — | Exclude operations whose path matches one of these patterns |
excludeTags | string[] | — | Exclude operations that carry any of these tags |
includeMethods | string[] | — | Include only operations with one of these HTTP methods |
includeOperationIds | string[] | — | Include only operations whose operationId matches one of these patterns |
includePaths | string[] | — | Include only operations whose path matches one of these patterns |
includeTags | string[] | — | Include only operations that carry at least one of these tags |
Config file
The generator reads openapi-to-typescript.config.ts, openapi-to-typescript.config.json or an "openapi-to-typescript" key in package.json. Whatever the format, the file has this shape:
import { defineConfig } from "@spartaficial/openapi-to-typescript";
export default defineConfig({
// Optional. Any of the 16 options marked "yes" above, applied to every entry in specs
defaults: {},
// Required. One entry per specification; an entry's own options override defaults
specs: [{ input: "openapi.yaml", outputTypes: "src/types.ts" }],
// Optional. How several entries are processed: "parallel" or "sequential"; default "parallel"
executionMode: "parallel",
});
defaults takes the options marked "yes" in the "In defaults" column; paths and name are always per entry. executionMode only matters when specs has more than one entry.