1+ use schemars:: transform:: Transform ;
2+
13use crate :: schema:: { InstanceType , Metadata , Schema , SchemaObject , SingleOrVec , NULL_SCHEMA } ;
24
35/// Take oneOf or anyOf subschema properties and move them them into the schema
@@ -11,7 +13,34 @@ use crate::schema::{InstanceType, Metadata, Schema, SchemaObject, SingleOrVec, N
1113/// - Each subschema has the type "object"
1214///
1315/// NOTE: This should work regardless of whether other hoisting has been performed or not.
14- pub ( crate ) fn hoist_properties_for_any_of_subschemas ( kube_schema : & mut SchemaObject ) {
16+ #[ derive( Debug , Clone ) ]
17+ pub struct PropertiesSchemaRewriter ;
18+
19+ impl Transform for PropertiesSchemaRewriter {
20+ fn transform ( & mut self , transform_schema : & mut schemars:: Schema ) {
21+ // Apply this (self) transform to all subschemas
22+ schemars:: transform:: transform_subschemas ( self , transform_schema) ;
23+
24+ let mut schema: SchemaObject = match serde_json:: from_value ( transform_schema. clone ( ) . to_value ( ) ) . ok ( )
25+ {
26+ // TODO (@NickLarsenNZ): At this point, we are seeing duplicate `title` when printing schema as json.
27+ // This is because `title` is specified under both `extensions` and `other`.
28+ Some ( schema) => schema,
29+ None => return ,
30+ } ;
31+
32+ hoist_properties_for_any_of_subschemas ( & mut schema) ;
33+
34+ // Convert back to schemars::Schema
35+ if let Ok ( schema) = serde_json:: to_value ( schema) {
36+ if let Ok ( transformed) = serde_json:: from_value ( schema) {
37+ * transform_schema = transformed;
38+ }
39+ }
40+ }
41+ }
42+
43+ fn hoist_properties_for_any_of_subschemas ( kube_schema : & mut SchemaObject ) {
1544 // Run some initial checks in case there is nothing to do
1645 let SchemaObject {
1746 subschemas : Some ( subschemas) ,
0 commit comments