Skip to content

Commit

Permalink
Fix a bug in dash api
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Sep 26, 2023
1 parent 89d3833 commit 209d23c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
8 changes: 4 additions & 4 deletions dash/api/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> },
Static {},
}

impl Default for ModelFieldKindObjectSpec {
Expand Down
33 changes: 12 additions & 21 deletions dash/controller/src/validator/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}]),
Expand Down Expand Up @@ -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::<BTreeSet<_>>();
let properties = properties
.keys()
.filter(|&property| property != "default")
.collect::<BTreeSet<_>>();
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(),
})
Expand Down Expand Up @@ -265,7 +256,7 @@ impl ModelFieldsParser {
"/metadata/labels/".into(),
"/metadata/name/".into(),
],
kind: ModelFieldKindObjectSpec::Static,
kind: ModelFieldKindObjectSpec::Static {},
},
attribute: ModelFieldAttributeSpec { optional: false },
};
Expand All @@ -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 },
};
Expand All @@ -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 },
};
Expand Down Expand Up @@ -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 },
};
Expand Down
10 changes: 6 additions & 4 deletions dash/provider/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)?;
Expand Down
14 changes: 12 additions & 2 deletions dash/provider/src/storage/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: _ } => {
Expand Down

0 comments on commit 209d23c

Please sign in to comment.