From f6e089555e8396969865d22aeb88f3b3ce6056db Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 6 Mar 2023 16:21:17 +0100 Subject: [PATCH] schema: verify property strings w/ new serde code Signed-off-by: Wolfgang Bumiller --- proxmox-schema/src/de/mod.rs | 6 +++++- proxmox-schema/src/schema.rs | 2 +- proxmox-schema/tests/schema_verification.rs | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/proxmox-schema/src/de/mod.rs b/proxmox-schema/src/de/mod.rs index 973bb95e..804ffccf 100644 --- a/proxmox-schema/src/de/mod.rs +++ b/proxmox-schema/src/de/mod.rs @@ -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); diff --git a/proxmox-schema/src/schema.rs b/proxmox-schema/src/schema.rs index 8bbadcf8..f0877067 100644 --- a/proxmox-schema/src/schema.rs +++ b/proxmox-schema/src/schema.rs @@ -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)?; diff --git a/proxmox-schema/tests/schema_verification.rs b/proxmox-schema/tests/schema_verification.rs index 09d7d87a..7df5d7a4 100644 --- a/proxmox-schema/tests/schema_verification.rs +++ b/proxmox-schema/tests/schema_verification.rs @@ -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"), ], )?;