|
1 | | -use crate::schema::{InstanceType, Schema, SchemaObject, SingleOrVec, NULL_SCHEMA}; |
| 1 | +use crate::schema::{InstanceType, Metadata, Schema, SchemaObject, SingleOrVec, NULL_SCHEMA}; |
2 | 2 |
|
3 | 3 | /// Take oneOf or anyOf subschema properties and move them them into the schema |
4 | 4 | /// properties. |
@@ -61,26 +61,26 @@ pub(crate) fn hoist_properties_for_any_of_subschemas(kube_schema: &mut SchemaObj |
61 | 61 | .collect::<Vec<_>>(); |
62 | 62 |
|
63 | 63 | 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. |
67 | 65 | subschema.instance_type.take(); |
68 | | - |
69 | | - // Set the schema type to object |
70 | 66 | kube_schema.instance_type = Some(SingleOrVec::Single(Box::new(InstanceType::Object))); |
71 | 67 |
|
| 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 | + |
72 | 72 | if let Some(object) = subschema.object.as_deref_mut() { |
73 | 73 | // Kubernetes doesn't allow variants to set additionalProperties |
74 | 74 | object.additional_properties.take(); |
75 | 75 |
|
76 | 76 | // For a tagged enum (oneOf), we need to preserve the variant description |
77 | 77 | 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() { |
79 | 79 | if let Some(Metadata { |
80 | 80 | description: Some(_), .. |
81 | | - }) = metadata.as_deref() |
| 81 | + }) = subschema_metadata.as_deref() |
82 | 82 | { |
83 | | - subschema.metadata = metadata |
| 83 | + property_schema.metadata = subschema_metadata |
84 | 84 | } |
85 | 85 | }; |
86 | 86 | } |
|
0 commit comments