After moving a spec from OpenAPI 3.0.3 to 3.1.0, nullable fields break older code generators
0 reputation · 16 May 2026, 16:37 UTC
0 reputation · 16 May 2026, 16:37 UTC
I maintain an OpenAPI document that describes a REST API consumed by several downstream teams, each running their own validation and code-generation pipelines. The spec currently declares openapi: 3.0.3 and uses nullable: true on a number of schema properties. I want to adopt 3.1.0, where nullability is expressed as a JSON Schema type union such as type: ["string", "null"], and the nullable keyword is no longer valid.
The uncertainty is that some consumers' generators and validators appear to apply 3.0 parsing rules regardless of the declared version field, so a 3.1-valid document risks being silently misread or rejected. I also cannot easily force every consumer to upgrade their toolchain on my schedule.
openapi version rather than defaulting to 3.0 semantics?nullable, that I should audit for before committing to the migration?35275 reputation · 17 May 2026, 01:52 UTC
There is no negotiation mechanism in OpenAPI: the openapi field is declarative, and many older tools hard-code 3.0 parsing regardless of what it says. The only reliable way to know whether a consumer's toolchain honors the version is to probe it empirically with a 3.1-only construct. Given that you cannot force upgrades, dual-publishing — authoring one version and mechanically generating the other — is the accepted workaround, but only if one document is a build artifact, not a second source of truth.
Don't trust that a tool "accepts" a 3.1 file; acceptance can mean it parsed the YAML and silently applied 3.0 semantics. Instead, send each consumer a minimal probe spec:
openapi: 3.1.0
info: { title: probe, version: 0.0.1 }
paths: {}
components:
schemas:
Probe:
type: object
properties:
maybeName:
type: ["string", "null"]
kind:
const: probe
Then check three things: the validator accepts the document, the generator produces a nullable type for maybeName (not a plain required string), and const is handled rather than dropped. A tool that validates but generates a non-nullable field is the dangerous case — it parsed successfully with wrong semantics. Cross-check probe results against each tool's release notes or issue tracker for explicit OpenAPI 3.1 / JSON Schema 2020-12 support claims.
Parallel 3.0.3 and 3.1.0 documents are the standard answer to mixed consumer toolchains. The dominant failure mode is drift between hand-maintained copies, so:
nullable: true is invalid, and a 3.0 tool fed type: ["string","null"] will typically reject or misread it, so CI should catch both directions.nullable is the visible break, but the schema dialect change to JSON Schema 2020-12 creates subtler ones:
minimum/maximum in 3.0. Converters usually handle this, but verify boundary payloads.enum.oneOf restructuring.items semantics differ subtly, so a converter can succeed syntactically while changing validation strictness.The key caution: automated converters may drop unsupported constructs rather than fail loudly. Audit the converter's output schema-by-schema; do not trust exit codes.
Tool support for 3.1 changes frequently, so treat any specific generator's behavior as unverified until probed — the probe approach above is deliberately tool-agnostic for that reason. If you can share which generators your downstream teams run, the recommendation on which version to author as the source may change, since some converters are stronger in one direction than the other.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.