schema: verify property strings w/ new serde code

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2023-03-06 16:21:17 +01:00 committed by Thomas Lamprecht
parent 12da5121ff
commit f6e089555e
3 changed files with 14 additions and 6 deletions

View File

@ -606,7 +606,11 @@ impl<'de, 'i> de::MapAccess<'de> for MapAccess<'de, 'i> {
.ok_or(Error::msg("bad default key"))?;
(Cow::Borrowed(key), Some(schema))
}
None => return Err(Error::msg("missing key")),
None => {
return Err(Error::msg(
"value without key, but schema does not define a default key",
))
}
},
};
let schema = schema.map(|(_optional, schema)| schema);

View File

@ -472,7 +472,7 @@ impl StringSchema {
}
}
ApiStringFormat::PropertyString(subschema) => {
subschema.parse_property_string(value)?;
crate::de::verify::verify(subschema, value)?;
}
ApiStringFormat::VerifyFn(verify_fn) => {
verify_fn(value)?;

View File

@ -158,7 +158,7 @@ fn verify_nested_property1() -> Result<(), Error> {
&value,
&[(
"ps1",
"Value without key, but schema does not define a default key.",
"value without key, but schema does not define a default key",
)],
)?;
@ -172,7 +172,11 @@ fn verify_nested_property2() -> Result<(), Error> {
test_verify(
&NESTED_PROPERTY_SCHEMA,
&value,
&[("ps1/abc", "schema does not allow additional properties.")],
&[
("ps1/abc", "schema does not allow additional properties"),
("ps1/prop1", "property is missing and it is not optional"),
("ps1/prop3", "property is missing and it is not optional"),
],
)?;
Ok(())
@ -186,8 +190,8 @@ fn verify_nested_property3() -> Result<(), Error> {
&NESTED_PROPERTY_SCHEMA,
&value,
&[
("ps1/prop1", "parameter is missing and it is not optional."),
("ps1/prop3", "parameter is missing and it is not optional."),
("ps1/prop1", "property is missing and it is not optional"),
("ps1/prop3", "property is missing and it is not optional"),
],
)?;