DEV Community

Jason Y. (dev_in_the_fog)
Jason Y. (dev_in_the_fog)

Posted on

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", "nullable": true }. OpenAPI 3.1 drops nullable in favor of standard JSON Schema { "type": ["string", "null"] } (or anyOf). Older 3.0-only generators miss the array form and omit .nullable() in generated Zod schemas.

2. exclusiveMinimum / exclusiveMaximum Changed From Boolean to Number

In 3.0, minimum: 0 paired with exclusiveMinimum: true. In 3.1, exclusiveMinimum: 0 carries the numeric bound directly. Validators expecting booleans either ignore the bound or produce NaN checks.

3. Sibling Keywords Next to $ref

OpenAPI 3.0 ignored sibling properties beside $ref; 3.1 permits description and annotations alongside $ref, which breaks naive reference resolvers.

Zero-Dependency Linter & Client-Side Converters

Because private internal OpenAPI specs shouldn't be uploaded to third-party web converters, I built a small zero-dependency MIT CLI (openapi-zod-lint) plus 0-byte-upload browser converters:

Top comments (1)

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

The nullable to type array change is the one that bites quietly. Generators just drop the null case.