mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-11 20:27:56 +00:00
AllOfSchema support in parse_property_string
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
12a6846a03
commit
adcbf7cab8
@ -838,8 +838,12 @@ pub fn parse_boolean(value_str: &str) -> Result<bool, Error> {
|
|||||||
|
|
||||||
/// Parse a complex property string (`ApiStringFormat::PropertyString`)
|
/// Parse a complex property string (`ApiStringFormat::PropertyString`)
|
||||||
pub fn parse_property_string(value_str: &str, schema: &'static Schema) -> Result<Value, Error> {
|
pub fn parse_property_string(value_str: &str, schema: &'static Schema) -> Result<Value, Error> {
|
||||||
match schema {
|
// helper for object/allof schemas:
|
||||||
Schema::Object(object_schema) => {
|
fn parse_object<T: Into<ParameterSchema>>(
|
||||||
|
value_str: &str,
|
||||||
|
schema: T,
|
||||||
|
default_key: Option<&'static str>,
|
||||||
|
) -> Result<Value, Error> {
|
||||||
let mut param_list: Vec<(String, String)> = vec![];
|
let mut param_list: Vec<(String, String)> = vec![];
|
||||||
let key_val_list: Vec<&str> = value_str
|
let key_val_list: Vec<&str> = value_str
|
||||||
.split(|c: char| c == ',' || c == ';')
|
.split(|c: char| c == ',' || c == ';')
|
||||||
@ -849,15 +853,21 @@ pub fn parse_property_string(value_str: &str, schema: &'static Schema) -> Result
|
|||||||
let kv: Vec<&str> = key_val.splitn(2, '=').collect();
|
let kv: Vec<&str> = key_val.splitn(2, '=').collect();
|
||||||
if kv.len() == 2 {
|
if kv.len() == 2 {
|
||||||
param_list.push((kv[0].trim().into(), kv[1].trim().into()));
|
param_list.push((kv[0].trim().into(), kv[1].trim().into()));
|
||||||
} else if let Some(key) = object_schema.default_key {
|
} else if let Some(key) = default_key {
|
||||||
param_list.push((key.into(), kv[0].trim().into()));
|
param_list.push((key.into(), kv[0].trim().into()));
|
||||||
} else {
|
} else {
|
||||||
bail!("Value without key, but schema does not define a default key.");
|
bail!("Value without key, but schema does not define a default key.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_parameter_strings(¶m_list, object_schema, true).map_err(Error::from)
|
parse_parameter_strings(¶m_list, schema, true).map_err(Error::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match schema {
|
||||||
|
Schema::Object(object_schema) => {
|
||||||
|
parse_object(value_str, object_schema, object_schema.default_key)
|
||||||
|
}
|
||||||
|
Schema::AllOf(all_of_schema) => parse_object(value_str, all_of_schema, None),
|
||||||
Schema::Array(array_schema) => {
|
Schema::Array(array_schema) => {
|
||||||
let mut array: Vec<Value> = vec![];
|
let mut array: Vec<Value> = vec![];
|
||||||
let list: Vec<&str> = value_str
|
let list: Vec<&str> = value_str
|
||||||
|
Loading…
Reference in New Issue
Block a user