-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Handle optional Vec and BTreeMap as Option<t> #41
Conversation
f22c161
to
36d4fe6
Compare
Previously, optional array properties are required in the generated struct, but skipped if serializing. This is incorrect behavior, since an empty Vec is not the same as not supplying a Vec. This breaks server-side apply-ing new resources to remove things from the Vec, as well as cases where a property is required in a one-of, but you actually want to send the empty Vec as one of those properties. This change instead makes it an Option<Vec<T>> with #[serde(default, skip_serializing_if = "Option::is_none")]. The above also applies to BTreeMaps. Resolves kube-rs#40 Signed-off-by: Alex Hunt <alex.hunt@materialize.com>
36d4fe6
to
1183a11
Compare
@@ -17,7 +17,6 @@ Requirements: | |||
## Features | |||
|
|||
- **Instantly queryable**: generated type uses [`kube-derive`](https://docs.rs/kube/latest/kube/derive.CustomResource.html) to provide api integration with `kube` | |||
- **Ergonomic Rust types**: `#[serde(default)]` on `Vec`/`BTreeMap` over `Option` wrapping |
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.
This breaks server-side apply-ing new resources to remove things from the Vec, as well as cases where a property is required in a one-of, but you actually want to send the empty Vec as one of those properties.
While there are ways to get around apply (json patch, merge patch), this definitely make the current setup less attractive. There's a similar issue in kube-rs on what we should do with it, but I think this is ultimately the right decision 😞
@@ -210,32 +210,14 @@ fn analyze_object_properties( | |||
docs: member_doc, | |||
}) | |||
} else { | |||
// option wrapping possibly needed if not required |
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.
ah lol, foreshadowing comment haunting me
#[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
pub groups: Vec<PrometheusRuleGroups>, |
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.
thanks for doing this, and regenerating the docs!
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.
No problem, thanks for reviewing it!
Previously, optional array properties are required in the generated struct, but skipped if serializing. This is incorrect behavior, since an empty Vec is not the same as not supplying a Vec.
This breaks server-side apply-ing new resources to remove things from the Vec, as well as cases where a property is required in a one-of, but you actually want to send the empty Vec as one of those properties.
This change instead makes it an Option<Vec> with #[serde(default, skip_serializing_if = "Option::is_none")].
The above also applies to BTreeMaps.
Resolves #40