-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'omitzero' support to mark optional fields #742
Add 'omitzero' support to mark optional fields #742
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #742 +/- ##
=======================================
Coverage 93.00% 93.00%
=======================================
Files 23 23
Lines 5246 5250 +4
=======================================
+ Hits 4879 4883 +4
Misses 315 315
Partials 52 52 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This pull request adds support for the new "omitzero" field tag introduced in go-1.24 to allow fields with a zero value to be omitted during JSON marshaling.
- Updated schema processing to treat fields tagged with "omitzero" as optional.
- Added tests for both "omitempty" and "omitzero" tag behavior.
- Updated documentation to mention the new tag.
Reviewed Changes
File | Description |
---|---|
schema.go | Integrated "omitzero" flag in required field logic |
schema_test.go | Added tests to verify behavior for "omitempty" and "omitzero" tags |
docs/docs/features/request-validation.md | Updated documentation examples to include "omitzero" tag |
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thank you @JasirZaeem 👍
@danielgtaylor Thanks for the great library :) |
Add support for using the new
omitzero
field tag introduced in go-1.24 to mark those fields as optional/not-requiredhttps://tip.golang.org/doc/go1.24#encodingjsonpkgencodingjson
Changes
omitzero
to mark field as optional inschema.go
omitempty
andomitzero
inschema_test.go
request-validation.md
docsLmk if there are other files/places that need changing for this change.