Skip to main content

openapi-to-zod options

Every configuration option of @spartaficial/openapi-to-zod: 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 Zod 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.

OptionTypeDefaultIn defaultsDescription
inputstringrequirednoPath to OpenAPI specification file (YAML or JSON)
outputTypesstringrequirednoOutput file path for the generated schemas and types, or for the types alone when outputZodSchemas is set
batchSizenumber > 010yesBatch size for parallel execution
cacheSizenumber > 01000yesCache size for pattern regex compilation
customDateTimeFormatRegexstring | RegExp—yesCustom regex pattern for date-time format validation
defaultNullablebooleanfalseyesTreat all properties as nullable by default when not explicitly specified
emptyObjectBehavior"strict" | "loose" | "record""loose"yesBehavior for empty object schemas (objects with no properties defined)
enumFormat"union" | "const-object""const-object"yesFormat for generating enums in TypeScript types (when using outputZodSchemas)
fileHeaderstring[]—yesCustom comment lines to add at the very top of generated files
ignoreHeadersstring[]—yesHeader parameters to ignore during schema generation
includeDescriptionsbooleantrueyesInclude JSDoc comments from schema descriptions
mode"strict" | "normal" | "loose""strict"yesObject validation mode
namestring—noA label for this specification entry
operationFiltersobject—yesFilter which operations to include/exclude from generation (see the table below)
outputstring—noDeprecated. Former name of outputTypes, accepted for backward compatibility
outputZodSchemasstring—noOutput path for Zod schemas when using separate type/schema files
prefixstring—yesPrefix to add to all generated type/schema names
refMappingsRecord<string, string>—yesRedirect remote $ref documents to local files, keyed by URL prefix
requestobject—yesRequest-specific options that override the top-level options (see the table below)
responseobject—yesResponse-specific options that override the top-level options (see the table below)
schemaType"all" | "request" | "response""all"yesGenerate the request shape, the response shape, or everything
showStatsbooleantrueyesShow generation statistics in output file
showWarningsbooleantrueyesEnable or disable warning messages during generation
stripPathPrefixstring—yesStrip a common prefix from all paths before generating operation-derived type names
stripSchemaPrefixstring | string[]—yesStrip a common prefix from all schema names before processing
suffixstring—yesSuffix to add to generated type/schema names
typeAssertionThresholdinteger >= 00yesComplexity threshold for switching to the double assertion (as unknown as) in generated schema declarations (only applies when outputZodSchemas is used)
useDescribebooleanfalseyesWhether to add .describe() calls for better error messages
useOperationIdbooleantrueyesWhether to use operationId from OpenAPI spec for operation-derived naming
uuidFormat"uuid" | "guid" | "uuidv1" | "uuidv2" | "uuidv3" | "uuidv4" | "uuidv5" | "uuidv6" | "uuidv7" | "uuidv8""uuid"yesUUID/GUID format for Zod validation

operationFilters​

Options of the operationFilters object. These are the operation filters every generator shares.

OptionTypeDefaultDescription
excludeDeprecatedbooleanfalseExclude operations marked as deprecated
excludeMethodsstring[]—Exclude operations with one of these HTTP methods
excludeOperationIdsstring[]—Exclude operations whose operationId matches one of these patterns
excludePathsstring[]—Exclude operations whose path matches one of these patterns
excludeTagsstring[]—Exclude operations that carry any of these tags
includeMethodsstring[]—Include only operations with one of these HTTP methods
includeOperationIdsstring[]—Include only operations whose operationId matches one of these patterns
includePathsstring[]—Include only operations whose path matches one of these patterns
includeTagsstring[]—Include only operations that carry at least one of these tags

request and response​

The request and response objects accept the same options, each applying to its own side of the exchange.

OptionTypeDefaultDescription
defaultNullablebooleanthe top-level defaultNullableAccepted for symmetry with the top-level option, but not applied: the top-level defaultNullable governs both contexts
emptyObjectBehavior"strict" | "loose" | "record"the top-level emptyObjectBehaviorAccepted for symmetry with the top-level option, but not applied: the top-level emptyObjectBehavior governs both contexts
includeDescriptionsbooleanthe top-level includeDescriptionsWhether to include descriptions as JSDoc comments
mode"strict" | "normal" | "loose"the top-level modeObject validation mode
useDescribebooleanthe top-level useDescribeWhether to add .describe() calls for better error messages

Config file​

The generator reads openapi-to-zod.config.ts, openapi-to-zod.config.json or an "openapi-to-zod" key in package.json. Whatever the format, the file has this shape:

import { defineConfig } from "@spartaficial/openapi-to-zod";

export default defineConfig({
// Optional. Any of the 25 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/schemas.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.