Commit 33101e8
fix: add omitempty to optional nullable fields
Fixes #2091
The `omitempty` JSON tag was not being added to optional nullable fields.
The condition `!p.Nullable && shouldOmitEmpty` explicitly prevented any
nullable field from receiving `omitempty`, even when the field was
optional (not required). This contradicted the documented behavior.
The fix removes the `!p.Nullable` guard so nullable fields follow the
same `omitempty` rules as non-nullable fields. The special-case
exception for the `nullable-type` output option is no longer needed
since the logic is now uniform.
Note: `x-go-type-skip-optional-pointer: true` on a nullable field
suppresses the pointer (generating `string` instead of `*string`) but
still correctly receives `omitempty` when the field is optional. Whether
skip-optional-pointer should be allowed to suppress the pointer on
nullable fields is a separate concern.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>1 parent 01d4fc0 commit 33101e8
4 files changed
Lines changed: 7 additions & 11 deletions
File tree
- internal/test
- issues/issue-1039/defaultbehaviour
- schemas
- pkg/codegen
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
759 | 759 | | |
760 | 760 | | |
761 | 761 | | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
| 762 | + | |
767 | 763 | | |
768 | 764 | | |
769 | 765 | | |
| |||
0 commit comments