Add associative map constraints and range refinement
This commit is contained in:
@@ -84,6 +84,16 @@ fn object(fields: &Map<String, Value>) -> Result<HostValue, String> {
|
||||
default,
|
||||
})
|
||||
}
|
||||
"Map" => {
|
||||
let value = fields
|
||||
.get("value")
|
||||
.ok_or_else(|| String::from("Map descriptor requires `value`"))?;
|
||||
Ok(HostValue::MapConstraint {
|
||||
value: Box::new(from_json(value)?),
|
||||
constraints,
|
||||
default,
|
||||
})
|
||||
}
|
||||
"Abstract" => Ok(HostValue::Abstract {
|
||||
constraints,
|
||||
default,
|
||||
@@ -217,6 +227,23 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converts_map_schema_descriptors() {
|
||||
let value = serde_json::json!({
|
||||
"$decodal": "Map",
|
||||
"value": { "$decodal": "Bool" },
|
||||
"default": {},
|
||||
});
|
||||
assert_eq!(
|
||||
from_json(&value).unwrap(),
|
||||
HostValue::MapConstraint {
|
||||
value: Box::new(HostValue::bool_type()),
|
||||
constraints: Vec::new(),
|
||||
default: Some(Box::new(HostValue::object([] as [(&str, HostValue); 0]))),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_null_values() {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user