From 69bee9524f9356927cf8b012f5436315635be59f Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 9 Feb 2021 09:06:39 +0100 Subject: [PATCH] api: add type_text to StringSchema --- proxmox/src/api/format.rs | 8 +++++++- proxmox/src/api/schema.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/proxmox/src/api/format.rs b/proxmox/src/api/format.rs index f7a2934b..24c0958f 100644 --- a/proxmox/src/api/format.rs +++ b/proxmox/src/api/format.rs @@ -80,7 +80,13 @@ fn test_wrap_text() { pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String { match schema { Schema::Null => String::from(""), // should not happen - Schema::String(_) => String::from(""), + Schema::String(string_schema) => { + if let Some(type_text) = string_schema.type_text { + String::from(type_text) + } else { + String::from("") + } + } Schema::Boolean(_) => String::from(""), Schema::Integer(integer_schema) => match (integer_schema.minimum, integer_schema.maximum) { (Some(min), Some(max)) => format!(" ({} - {})", min, max), diff --git a/proxmox/src/api/schema.rs b/proxmox/src/api/schema.rs index 068c711b..86bcb7bd 100644 --- a/proxmox/src/api/schema.rs +++ b/proxmox/src/api/schema.rs @@ -259,6 +259,8 @@ pub struct StringSchema { pub max_length: Option, /// Optional microformat. pub format: Option<&'static ApiStringFormat>, + /// A text representation of the format/type (used to generate documentation). + pub type_text: Option<&'static str>, } impl StringSchema { @@ -269,6 +271,7 @@ impl StringSchema { min_length: None, max_length: None, format: None, + type_text: None, } } @@ -282,6 +285,11 @@ impl StringSchema { self } + pub const fn type_text(mut self, type_text: &'static str) -> Self { + self.type_text = Some(type_text); + self + } + pub const fn min_length(mut self, min_length: usize) -> Self { self.min_length = Some(min_length); self