@@ -2,9 +2,12 @@ use serde_json::Value;
22
33use 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.
811pub ( 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