From 099949456483b971454767d7cf061d3336bf1368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Wed, 15 Sep 2021 15:36:34 +0200 Subject: [PATCH] schema: add extra info to array parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it's not immediately obvious that they can be specified more than once otherwise. Signed-off-by: Fabian Grünbichler Signed-off-by: Thomas Lamprecht --- proxmox/src/api/format.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/proxmox/src/api/format.rs b/proxmox/src/api/format.rs index a362b215..64fcd0af 100644 --- a/proxmox/src/api/format.rs +++ b/proxmox/src/api/format.rs @@ -134,15 +134,15 @@ pub fn get_property_description( ) -> String { let type_text = get_schema_type_text(schema, style); - let (descr, default) = match schema { - Schema::Null => ("null", None), - Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned())), - Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string())), - Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string())), - Schema::Number(ref schema) => (schema.description, schema.default.map(|v| v.to_string())), - Schema::Object(ref schema) => (schema.description, None), - Schema::AllOf(ref schema) => (schema.description, None), - Schema::Array(ref schema) => (schema.description, None), + let (descr, default, extra) = match schema { + Schema::Null => ("null", None, None), + Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned()), None), + Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None), + Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None), + Schema::Number(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None), + Schema::Object(ref schema) => (schema.description, None, None), + Schema::AllOf(ref schema) => (schema.description, None, None), + Schema::Array(ref schema) => (schema.description, None, Some(String::from("Can be specified more than once."))), }; let default_text = match default { @@ -150,6 +150,11 @@ pub fn get_property_description( None => String::new(), }; + let descr = match extra { + Some(extra) => format!("{} {}", descr, extra), + None => String::from(descr), + }; + if format == DocumentationFormat::ReST { let mut text = match style { ParameterDisplayStyle::Config => { @@ -169,7 +174,7 @@ pub fn get_property_description( } }; - text.push_str(&wrap_text("", " ", descr, 80)); + text.push_str(&wrap_text("", " ", &descr, 80)); text.push('\n'); text @@ -184,7 +189,7 @@ pub fn get_property_description( let mut text = format!(" {:-10} {}{}", display_name, type_text, default_text); let indent = " "; text.push('\n'); - text.push_str(&wrap_text(indent, indent, descr, 80)); + text.push_str(&wrap_text(indent, indent, &descr, 80)); text }