🐛 Handle omitzero in OneOf constraint validation#1375
🐛 Handle omitzero in OneOf constraint validation#1375HadrienPatte wants to merge 1 commit intokubernetes-sigs:mainfrom
omitzero in OneOf constraint validation#1375Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: HadrienPatte The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @HadrienPatte! |
|
Hi @HadrienPatte. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
JoelSpeed
left a comment
There was a problem hiding this comment.
Change seems reasonable to me, but can you please add some tests to demonstrate the new behaviour and prevent future regressions
The `OneOf`/`AtMostOneOf`/`AtLeastOneOf` constraint validation rejects fields that lack the `omitempty` json tag, since such fields would be marked as required, conflicting with being part of a `OneOf` group. However, `omitzero` (supported since [Go 1.24](https://go.dev/doc/go1.24#encodingjsonpkgencodingjson) via `encoding/json`) serves the same serialization purpose: the field is omitted when it holds its zero value. The current check does not recognize `omitzero`, causing a false positive error for valid field declarations. Example false positive error: ``` field endpointSelector is part of OneOf constraint and must have omitempty tag ``` Signed-off-by: Hadrien Patte <[email protected]>
|
Updated to add tests |
The
OneOf/AtMostOneOf/AtLeastOneOfconstraint validation rejects fields that lack theomitemptyjson tag, since such fields would be marked as required, conflicting with being part of aOneOfgroup.However,
omitzero(supported since Go 1.24 viaencoding/json) serves the same serialization purpose: the field is omitted when it holds its zero value. The current check does not recognizeomitzero, causing a false positive error for valid field declarations.Example false positive error: