diff --git a/dash/api/src/model.rs b/dash/api/src/model.rs index a2cc2451..bcf3a6e0 100644 --- a/dash/api/src/model.rs +++ b/dash/api/src/model.rs @@ -639,13 +639,13 @@ impl Default for ModelFieldKindStringSpec { } #[derive( - Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, + Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] #[serde(rename_all = "camelCase")] pub enum ModelFieldKindObjectSpec { - Dynamic, - Enumerate, - Static, + Dynamic {}, + Enumerate { choices: Vec }, + Static {}, } impl Default for ModelFieldKindObjectSpec { diff --git a/dash/controller/src/validator/model.rs b/dash/controller/src/validator/model.rs index 7f8fa7c5..cc24ec74 100644 --- a/dash/controller/src/validator/model.rs +++ b/dash/controller/src/validator/model.rs @@ -30,7 +30,7 @@ impl<'namespace, 'kube> ModelValidator<'namespace, 'kube> { name: "/".into(), kind: ModelFieldKindNativeSpec::Object { children: Default::default(), - kind: ModelFieldKindObjectSpec::Dynamic, + kind: ModelFieldKindObjectSpec::Dynamic {}, }, attribute: ModelFieldAttributeSpec { optional: true }, }]), @@ -199,25 +199,16 @@ impl ModelFieldsParser { self.parse_json_property_aggregation(&name, prop.properties.as_ref())?; Some(ModelFieldKindNativeSpec::Object { - kind: match prop.one_of.as_ref().zip(prop.properties.as_ref()) { - Some((one_of, properties)) => { - let one_of = one_of + kind: match prop.one_of.as_ref() { + Some(one_of) => ModelFieldKindObjectSpec::Enumerate { + choices: one_of .iter() .filter_map(|one_of| one_of.required.as_ref()) .flatten() - .collect::>(); - let properties = properties - .keys() - .filter(|&property| property != "default") - .collect::>(); - if one_of == properties { - ModelFieldKindObjectSpec::Enumerate - } else { - warn!("partial oneOf property is not supported: {name:?}"); - ModelFieldKindObjectSpec::Static - } - } - None => ModelFieldKindObjectSpec::Static, + .cloned() + .collect(), + }, + None => ModelFieldKindObjectSpec::Static {}, }, children: children.into_iter().collect(), }) @@ -265,7 +256,7 @@ impl ModelFieldsParser { "/metadata/labels/".into(), "/metadata/name/".into(), ], - kind: ModelFieldKindObjectSpec::Static, + kind: ModelFieldKindObjectSpec::Static {}, }, attribute: ModelFieldAttributeSpec { optional: false }, }; @@ -276,7 +267,7 @@ impl ModelFieldsParser { name: name.to_string(), kind: ModelFieldKindNativeSpec::Object { children: vec![], - kind: ModelFieldKindObjectSpec::Dynamic, + kind: ModelFieldKindObjectSpec::Dynamic {}, }, attribute: ModelFieldAttributeSpec { optional: false }, }; @@ -298,7 +289,7 @@ impl ModelFieldsParser { name: name.to_string(), kind: ModelFieldKindNativeSpec::Object { children: vec![], - kind: ModelFieldKindObjectSpec::Dynamic, + kind: ModelFieldKindObjectSpec::Dynamic {}, }, attribute: ModelFieldAttributeSpec { optional: false }, }; @@ -474,7 +465,7 @@ impl ModelFieldsParser { name: name.to_string(), kind: ModelFieldKindNativeSpec::Object { children: children.into_iter().collect(), - kind: ModelFieldKindObjectSpec::Static, + kind: ModelFieldKindObjectSpec::Static {}, }, attribute: ModelFieldAttributeSpec { optional: false }, }; diff --git a/dash/provider/src/input.rs b/dash/provider/src/input.rs index 420fdc0f..45bf0914 100644 --- a/dash/provider/src/input.rs +++ b/dash/provider/src/input.rs @@ -371,11 +371,12 @@ impl InputTemplate { self.update_field_value_impl(storage, input, optional).await } Value::Object(children) => match kind { - ModelFieldKindObjectSpec::Dynamic => { + ModelFieldKindObjectSpec::Dynamic {} => { *field = Value::Object(children); Ok(()) } - ModelFieldKindObjectSpec::Enumerate | ModelFieldKindObjectSpec::Static => { + ModelFieldKindObjectSpec::Enumerate { choices: _ } + | ModelFieldKindObjectSpec::Static {} => { for (child, value) in children.into_iter() { let child = InputField::sub_object(&name, &child, value); self.update_field_value_impl(storage, child, optional) @@ -803,11 +804,12 @@ impl<'a> ItemTemplate<'a> { }, ModelFieldKindNativeSpec::Object { children: _, kind } => match value { Value::Object(children) => match kind { - ModelFieldKindObjectSpec::Dynamic => { + ModelFieldKindObjectSpec::Dynamic {} => { *field = Value::Object(children); Ok(()) } - ModelFieldKindObjectSpec::Enumerate | ModelFieldKindObjectSpec::Static => { + ModelFieldKindObjectSpec::Enumerate { choices: _ } + | ModelFieldKindObjectSpec::Static {} => { for (child, value) in children.into_iter() { let child = InputField::sub_object(&name, &child, value); self.update_field_value_impl(child, optional)?; diff --git a/dash/provider/src/storage/db.rs b/dash/provider/src/storage/db.rs index 29b811af..8bc3a6e4 100644 --- a/dash/provider/src/storage/db.rs +++ b/dash/provider/src/storage/db.rs @@ -605,11 +605,21 @@ fn convert_field_to_column( ModelFieldKindNativeSpec::Object { children: _, kind } => { // attribute: type match kind { - ModelFieldKindObjectSpec::Dynamic => { + ModelFieldKindObjectSpec::Dynamic {} => { column.json(); Ok(Some(column)) } - ModelFieldKindObjectSpec::Enumerate | ModelFieldKindObjectSpec::Static => Ok(None), + ModelFieldKindObjectSpec::Enumerate { choices } => { + // attribute: default + if let Some(default) = choices.first() { + column.default(default); + } + + // attribute: choices + column.enumeration(name.clone(), choices.iter().map(RuntimeIden::from_str)); + Ok(Some(column)) + } + ModelFieldKindObjectSpec::Static {} => Ok(None), } } ModelFieldKindNativeSpec::ObjectArray { children: _ } => {