Skip to content

Commit 26146ea

Browse files
committed
Revert "refactor: Simplify description preservation and type dropping"
This reverts commit dcbe17e.
1 parent 11a8ddc commit 26146ea

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

kube-core/src/schema/transform_properties.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,30 @@ pub(crate) fn hoist_properties_for_any_of_subschemas(kube_schema: &mut SchemaObj
6161
.collect::<Vec<_>>();
6262

6363
for subschema in subschemas {
64-
// Drop the "type" field on subschema. It needs to be set to "object" on the schema.
64+
// This will clear out any objects that don't have required/properties fields (so that it
65+
// appears as: {}).
66+
let metadata = subschema.metadata.take();
6567
subschema.instance_type.take();
66-
kube_schema.instance_type = Some(SingleOrVec::Single(Box::new(InstanceType::Object)));
6768

68-
// Drop the description for untagged enum variants.
69-
// This (along with the dropping of the "type" above) will allow for empty variants ({}).
70-
if !preserve_description {
71-
subschema.metadata.take();
72-
}
69+
// Set the schema type to object
70+
kube_schema.instance_type = Some(SingleOrVec::Single(Box::new(InstanceType::Object)));
7371

7472
if let Some(object) = subschema.object.as_deref_mut() {
7573
// Kubernetes doesn't allow variants to set additionalProperties
7674
object.additional_properties.take();
7775

76+
// For a tagged enum (oneOf), we need to preserve the variant description
77+
if preserve_description {
78+
if let Some(Schema::Object(subschema)) = object.properties.values_mut().next() {
79+
if let Some(Metadata {
80+
description: Some(_), ..
81+
}) = metadata.as_deref()
82+
{
83+
subschema.metadata = metadata
84+
}
85+
};
86+
}
87+
7888
// If subschema properties are set, hoist them to the schema properties.
7989
// This will panic if duplicate properties are encountered that do not have the same
8090
// shape. That can happen when the untagged enum variants each refer to structs which

0 commit comments

Comments
 (0)