Skip to content

Commit 11a8ddc

Browse files
committed
docs: Revise doc comments
1 parent 925a8e3 commit 11a8ddc

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

kube-core/src/schema/transform_any_of.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ mod tests {
9898
"description": "First variant doc-comment",
9999
"type": "string",
100100
"enum": [
101-
"A"
102-
]
101+
"A"
102+
]
103103
},
104104
{
105105
"description": "Second variant doc-comment",

kube-core/src/schema/transform_optional_enum_with_null.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ use serde_json::Value;
22

33
use super::SchemaObject;
44

5-
/// A Option<Enum> without any descriptions has `nullable` set to `true` as well as a trailing
6-
/// `null` enum variant. We remove the trailing enum variant as it's not needed for Kubernetes and
7-
/// makes the CRD more compact by removing duplicated information.
5+
/// Drop trailing null on optional enums.
6+
///
7+
/// The nullability is already indicated when "nullable" is set to true.
8+
///
9+
/// NOTE: The trailing null is removed because it's not needed by Kubernetes
10+
/// and makes the CRD more compact by removing redundant information.
811
pub(crate) fn remove_optional_enum_null_variant(kube_schema: &mut SchemaObject) {
912
let SchemaObject {
1013
enum_values: Some(enum_values),
@@ -15,14 +18,11 @@ pub(crate) fn remove_optional_enum_null_variant(kube_schema: &mut SchemaObject)
1518
return;
1619
};
1720

18-
// It only makes sense to remove `null` enum values in case the enum is nullable (thus optional)
19-
// This is a safety mechanism, "nullable" should always be set to true, if one enum variant is
20-
// null.
21+
// For added safety, check nullability. It should always be true when there is a null variant.
2122
if let Some(Value::Bool(true)) = extensions.get("nullable") {
22-
// Don't remove the single last enum variant. This often happens for `Option<XXX>`, which is
23-
// represented as `"anyOf": [XXX, {"enum": [null], "optional": true}]`.
24-
// We need to keep `"enum": [null]` (as opposed to `"enum": []`), because other hoisting
25-
// code uses `kube::core::NULL_SCHEMA` to detect null variants.
23+
// Don't drop the null entry if it is the only thing in the enum.
24+
// This is because other hoisting code depends on `kube::core::NULL_SCHEMA` to detect null
25+
// variants.
2626
if enum_values.len() > 1 {
2727
enum_values.retain(|enum_value| enum_value != &Value::Null);
2828
}

0 commit comments

Comments
 (0)