3 Breaking Differences Between OpenAPI 3.0 and 3.1 That Trip Up TypeScript & Zod Codegen
Upgrading FastAPI or Springdoc to emit OpenAPI 3.1.0 often breaks existing TypeScript and Zod generators silently—fields start typing as unknown , or runtime validation rejects valid null payloads. Because OpenAPI 3.1 aligned directly with JSON Schema Draft 2020-12, three schema constructs changed shape. 1. nullable: true Was Replaced by Type Arrays OpenAPI 3.0 used { "type": "string",…
Upgrading FastAPI or Springdoc to emit OpenAPI 3.1.0 often results in silent breaking changes for TypeScript and Zod generators. Fields may be typed as unknown, or runtime validation may reject valid null payloads. This occurs because OpenAPI 3.1 directly aligns with JSON Schema Draft 2020-12, leading to three schema constructs changing shape.
First, the nullable: true option was replaced by the type arrays format in OpenAPI 3.1. Instead of { "type": "string", "nullable": true }, OpenAPI 3.1 uses { "type": ["string", "null"] } (or anyOf). Older 3.0-only generators fail to recognize this array form and omit .nullable() in generated Zod schemas.
Second, exclusiveMinimum and exclusiveMaximum have changed from boolean to numeric values in OpenAPI 3.1. In 3.0, minimum: 0 paired with exclusiveMinimum: true. In contrast, 3.1 directly incorporates the numeric bound with exclusiveMinimum: 0. Validators anticipating boolean inputs may disregard the bound or generate erroneous NaN checks.
Finally, sibling keywords next to $ref have been permitted in OpenAPI 3.1. Unlike 3.0, which ignored properties adjacent to $ref, 3.1 allows description and annotations alongside $ref. This change breaks naive reference resolvers, as these properties are now part of the schema structure.
For developers seeking a zero-dependency solution, a MIT-licensed CLI tool called openapi-zod-lint has been created. Additionally, browser converters for zero-upload use are available: Open-Source CLI (openapi-zod-lint, MIT) at https://github.com/JangYS0/openapi-zod-lint, Browser OpenAPI Converter (0B upload) at https://global-utils.com/en/openapi-converter, JSON to Zod Converter at https://global-utils.com/en/json-to-zod, and JSON to TypeScript Converter at https://global-utils.com/en/json-to-ts.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to