Skip to content

Commit

Permalink
Fix some bugs in dash
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Sep 25, 2023
1 parent eaa37a6 commit 0be3cb5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dash/api/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl Default for ModelFieldKindStringSpec {
#[serde(rename_all = "camelCase")]
pub enum ModelFieldKindObjectSpec {
Dynamic,
OneOfStatic,
Enumerate,
Static,
}

Expand Down
15 changes: 9 additions & 6 deletions dash/controller/src/validator/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,21 @@ impl ModelFieldsParser {
self.parse_json_property_aggregation(&name, prop.properties.as_ref())?;

Some(ModelFieldKindNativeSpec::Object {
kind: match prop.one_of.as_ref() {
Some(one_of) => {
kind: match prop.one_of.as_ref().zip(prop.properties.as_ref()) {
Some((one_of, properties)) => {
let one_of = one_of
.iter()
.filter_map(|one_of| one_of.required.as_ref())
.flatten()
.cloned()
.collect::<BTreeSet<_>>();
if children == one_of {
ModelFieldKindObjectSpec::OneOfStatic
let properties = properties
.keys()
.filter(|&property| property != "default")
.collect::<BTreeSet<_>>();
if one_of == properties {
ModelFieldKindObjectSpec::Enumerate
} else {
warn!("partial oneOf property is not supported");
warn!("partial oneOf property is not supported for {name:?}: {format:?}");
ModelFieldKindObjectSpec::Static
}
}
Expand Down
37 changes: 24 additions & 13 deletions dash/provider/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,25 @@ impl InputTemplate {
*field = Value::Null;
Ok(())
}
ModelFieldKindNativeSpec::Boolean { default: _ } => {
if value.is_boolean() {
*field = value;
ModelFieldKindNativeSpec::Boolean { default: _ } => match value {
Value::Bool(value) => {
*field = Value::Bool(value);
Ok(())
} else {
assert_optional(&name, &value, &base_field.parsed, optional)
}
}
Value::String(value) => {
*field = Value::Bool(value.parse()?);
Ok(())
}
value => assert_optional(&name, &value, &base_field.parsed, optional),
},
ModelFieldKindNativeSpec::Integer {
default: _,
minimum,
maximum,
} => match value.as_i64() {
} => match value
.as_i64()
.or_else(|| value.as_str().and_then(|value| value.parse().ok()))
{
Some(value_number) => {
assert_cmp(
&name,
Expand All @@ -241,7 +247,7 @@ impl InputTemplate {
Ordering::Less,
)?;

*field = value;
*field = Value::Number(value_number.into());
Ok(())
}
None => assert_optional(&name, &value, &base_field.parsed, optional),
Expand All @@ -250,8 +256,13 @@ impl InputTemplate {
default: _,
minimum,
maximum,
} => match value.as_f64().map(Into::into) {
Some(value_number) => {
} => match value
.as_f64()
.or_else(|| value.as_str().and_then(|value| value.parse().ok()))
.map(Number::from)
.and_then(|value| Some((value, ::serde_json::Number::from_f64(value.0)?)))
{
Some((value_number, value)) => {
assert_cmp(
&name,
&value_number,
Expand All @@ -269,7 +280,7 @@ impl InputTemplate {
Ordering::Less,
)?;

*field = value;
*field = Value::Number(value);
Ok(())
}
None => assert_optional(&name, &value, &base_field.parsed, optional),
Expand Down Expand Up @@ -364,7 +375,7 @@ impl InputTemplate {
*field = Value::Object(children);
Ok(())
}
ModelFieldKindObjectSpec::OneOfStatic | ModelFieldKindObjectSpec::Static => {
ModelFieldKindObjectSpec::Enumerate | 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 @@ -796,7 +807,7 @@ impl<'a> ItemTemplate<'a> {
*field = Value::Object(children);
Ok(())
}
ModelFieldKindObjectSpec::OneOfStatic | ModelFieldKindObjectSpec::Static => {
ModelFieldKindObjectSpec::Enumerate | 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
4 changes: 1 addition & 3 deletions dash/provider/src/storage/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,7 @@ fn convert_field_to_column(
column.json();
Ok(Some(column))
}
ModelFieldKindObjectSpec::OneOfStatic | ModelFieldKindObjectSpec::Static => {
Ok(None)
}
ModelFieldKindObjectSpec::Enumerate | ModelFieldKindObjectSpec::Static => Ok(None),
}
}
ModelFieldKindNativeSpec::ObjectArray { children: _ } => {
Expand Down
1 change: 1 addition & 0 deletions dash/router/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions kiss/plugin/src/routes/box/power/batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 0be3cb5

Please sign in to comment.