Skip to content

Commit 75c7ffa

Browse files
committed
refactor: Revise code after reverting
1 parent 26146ea commit 75c7ffa

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

kube-core/src/schema/transform_properties.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::schema::{InstanceType, Schema, SchemaObject, SingleOrVec, NULL_SCHEMA};
1+
use crate::schema::{InstanceType, Metadata, Schema, SchemaObject, SingleOrVec, NULL_SCHEMA};
22

33
/// Take oneOf or anyOf subschema properties and move them them into the schema
44
/// properties.
@@ -61,26 +61,26 @@ pub(crate) fn hoist_properties_for_any_of_subschemas(kube_schema: &mut SchemaObj
6161
.collect::<Vec<_>>();
6262

6363
for subschema in subschemas {
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();
64+
// Drop the "type" field on subschema. It needs to be set to "object" on the schema.
6765
subschema.instance_type.take();
68-
69-
// Set the schema type to object
7066
kube_schema.instance_type = Some(SingleOrVec::Single(Box::new(InstanceType::Object)));
7167

68+
// Take the description (which will be preserved for tagged enums further down).
69+
// This (along with the dropping of the "type" above) will allow for empty variants ({}).
70+
let subschema_metadata = subschema.metadata.take();
71+
7272
if let Some(object) = subschema.object.as_deref_mut() {
7373
// Kubernetes doesn't allow variants to set additionalProperties
7474
object.additional_properties.take();
7575

7676
// For a tagged enum (oneOf), we need to preserve the variant description
7777
if preserve_description {
78-
if let Some(Schema::Object(subschema)) = object.properties.values_mut().next() {
78+
if let Some(Schema::Object(property_schema)) = object.properties.values_mut().next() {
7979
if let Some(Metadata {
8080
description: Some(_), ..
81-
}) = metadata.as_deref()
81+
}) = subschema_metadata.as_deref()
8282
{
83-
subschema.metadata = metadata
83+
property_schema.metadata = subschema_metadata
8484
}
8585
};
8686
}

0 commit comments

Comments
 (0)