schema: add extra info to array parameters

it's not immediately obvious that they can be specified more than once
otherwise.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-09-15 15:36:34 +02:00 committed by Thomas Lamprecht
parent 5f5a5194de
commit 0999494564

View File

@ -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
}