From 4c741b67c77cbde86acb01f406fbf3eb2c314994 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 8 Feb 2021 09:13:55 +0100 Subject: [PATCH] api: add dump_enum_properties(), make dump_api_parameter pub --- proxmox/src/api/format.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/proxmox/src/api/format.rs b/proxmox/src/api/format.rs index 2ce95974..3ec58be4 100644 --- a/proxmox/src/api/format.rs +++ b/proxmox/src/api/format.rs @@ -1,6 +1,6 @@ //! Module to generate and format API Documenation -use anyhow::Error; +use anyhow::{bail, Error}; use std::io::Write; @@ -158,7 +158,27 @@ pub fn get_property_description( } } -fn dump_api_parameters(param: &dyn ObjectSchemaType) -> String +/// Generate ReST Documentaion for enumeration. +pub fn dump_enum_properties(schema: &Schema) -> Result { + + let mut res = String::new(); + + if let Schema::String(StringSchema { + format: Some(ApiStringFormat::Enum(variants)), .. + }) = schema { + for item in variants.iter() { + res.push_str(&format!(":``{}``: ", item.value)); + let descr = wrap_text("", " ", item.description, 80); + res.push_str(&descr); + res.push('\n'); + } + return Ok(res); + } + + bail!("dump_enum_properties failed - not an enum"); +} + +pub fn dump_api_parameters(param: &dyn ObjectSchemaType) -> String where I: Iterator, {