schema: use inline named params in format macro calls

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2025-01-28 14:19:13 +01:00
parent 703c2dee04
commit c0641c6e13
2 changed files with 15 additions and 19 deletions

View File

@ -142,7 +142,7 @@ pub fn dump_properties(
skip: &[&str], skip: &[&str],
) -> String { ) -> String {
let mut res = String::new(); let mut res = String::new();
let next_indent = format!(" {}", indent); let next_indent = format!(" {indent}");
let mut required_list: Vec<String> = Vec::new(); let mut required_list: Vec<String> = Vec::new();
let mut optional_list: Vec<String> = Vec::new(); let mut optional_list: Vec<String> = Vec::new();
@ -156,8 +156,8 @@ pub fn dump_properties(
get_property_description(prop, schema, style, DocumentationFormat::ReST); get_property_description(prop, schema, style, DocumentationFormat::ReST);
if !indent.is_empty() { if !indent.is_empty() {
param_descr = format!("{}{}", indent, param_descr); // indent first line param_descr = format!("{indent}{param_descr}"); // indent first line
param_descr = param_descr.replace('\n', &format!("\n{}", indent)); // indent rest param_descr = param_descr.replace('\n', &format!("\n{indent}")); // indent rest
} }
if style == ParameterDisplayStyle::Config { if style == ParameterDisplayStyle::Config {
@ -339,15 +339,15 @@ pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> S
} }
Schema::Boolean(_) => String::from("<boolean>"), Schema::Boolean(_) => String::from("<boolean>"),
Schema::Integer(integer_schema) => match (integer_schema.minimum, integer_schema.maximum) { Schema::Integer(integer_schema) => match (integer_schema.minimum, integer_schema.maximum) {
(Some(min), Some(max)) => format!("<integer> ({} - {})", min, max), (Some(min), Some(max)) => format!("<integer> ({min} - {max})"),
(Some(min), None) => format!("<integer> ({} - N)", min), (Some(min), None) => format!("<integer> ({min} - N)"),
(None, Some(max)) => format!("<integer> (-N - {})", max), (None, Some(max)) => format!("<integer> (-N - {max})"),
_ => String::from("<integer>"), _ => String::from("<integer>"),
}, },
Schema::Number(number_schema) => match (number_schema.minimum, number_schema.maximum) { Schema::Number(number_schema) => match (number_schema.minimum, number_schema.maximum) {
(Some(min), Some(max)) => format!("<number> ({} - {})", min, max), (Some(min), Some(max)) => format!("<number> ({min} - {max})"),
(Some(min), None) => format!("<number> ({} - N)", min), (Some(min), None) => format!("<number> ({min} - N)"),
(None, Some(max)) => format!("<number> (-N - {})", max), (None, Some(max)) => format!("<number> (-N - {max})"),
_ => String::from("<number>"), _ => String::from("<number>"),
}, },
Schema::Object(_) => String::from("<object>"), Schema::Object(_) => String::from("<object>"),
@ -362,7 +362,7 @@ pub fn get_property_string_type_text(schema: &Schema) -> String {
Schema::Object(object_schema) => get_object_type_text(object_schema), Schema::Object(object_schema) => get_object_type_text(object_schema),
Schema::Array(array_schema) => { Schema::Array(array_schema) => {
let item_type = get_simple_type_text(array_schema.items, true); let item_type = get_simple_type_text(array_schema.items, true);
format!("[{}, ...]", item_type) format!("[{item_type}, ...]")
} }
_ => panic!("get_property_string_type_text: expected array or object"), _ => panic!("get_property_string_type_text: expected array or object"),
} }
@ -374,12 +374,12 @@ fn get_object_type_text(object_schema: &ObjectSchema) -> String {
let mut add_part = |name, optional, schema| { let mut add_part = |name, optional, schema| {
let tt = get_simple_type_text(schema, false); let tt = get_simple_type_text(schema, false);
let text = if parts.is_empty() { let text = if parts.is_empty() {
format!("{}={}", name, tt) format!("{name}={tt}")
} else { } else {
format!(",{}={}", name, tt) format!(",{name}={tt}")
}; };
if optional { if optional {
parts.push(format!("[{}]", text)); parts.push(format!("[{text}]"));
} else { } else {
parts.push(text); parts.push(text);
} }
@ -459,7 +459,7 @@ pub fn dump_api_return_schema(returns: &ReturnType, style: ParameterDisplayStyle
}; };
let type_text = get_schema_type_text(schema, style); let type_text = get_schema_type_text(schema, style);
let _ = write!(res, "**{}**\n\n", type_text); let _ = write!(res, "**{type_text}**\n\n");
match schema { match schema {
Schema::Null => { Schema::Null => {

View File

@ -1263,11 +1263,7 @@ pub fn dump_section_config(config: &SectionConfig) -> String {
use std::fmt::Write as _; use std::fmt::Write as _;
let description = wrap_text("", "", properties.description(), 80); let description = wrap_text("", "", properties.description(), 80);
let _ = write!( let _ = write!(res, "\n**Section type** \'``{name}``\': {description}\n\n");
res,
"\n**Section type** \'``{}``\': {}\n\n",
name, description
);
} }
res.push_str(&dump_properties( res.push_str(&dump_properties(