Repository navigation
Keep required nullable properties as pointers that write null - #166
Merged
Merged
Conversation
cubahno
force-pushed
the
ig/fix-req-nullable-anyof
branch
from
October 8, 2026 09:36
94c7c94 to
80c9c5b
Compare
cubahno
marked this pull request as ready for review
October 8, 2026 09:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A required property declared as
anyOf: [T, {type: "null"}], which Pydantic and FastAPI emit forT | Nonewithout a default, was generated as a plainT. Building the union saw the null option, but the object's property loop then recomputed nullability from the property's owntype, which ananyOfdoesn't have. So anullfrom the server decoded to the zero value and was sent back as0001-01-01T00:00:00Zor"". Separately, every required nullable property gotomitempty, so a nil value dropped a key the schema requires instead of writingnull. That one already applied totype: [T, "null"]andnullable: true.What changes
anyOforoneOflists{type: "null"}next to a single other type is nullable, so a required one becomes a pointer:UpdatedAt *time.Time.omitempty, so a nil pointer encodes asnull. That holds fortype: [T, "null"]andnullable: truetoo, and for theMarshalJSONgenerated for types withadditionalPropertiesor a union next to their properties.omitempty. Optional properties, unions of two or more types besides null, and request parameters generate as before.Constraints.RequiredKeysays whether the object requires the property's key, andProperty.OmitsNilwhether a nil value leaves the key out.Fixes #162