mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-19 08:18:17 +00:00
api: add type_text to StringSchema
This commit is contained in:
parent
4efbdd79ef
commit
69bee9524f
@ -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("<null>"), // should not happen
|
||||
Schema::String(_) => String::from("<string>"),
|
||||
Schema::String(string_schema) => {
|
||||
if let Some(type_text) = string_schema.type_text {
|
||||
String::from(type_text)
|
||||
} else {
|
||||
String::from("<string>")
|
||||
}
|
||||
}
|
||||
Schema::Boolean(_) => String::from("<boolean>"),
|
||||
Schema::Integer(integer_schema) => match (integer_schema.minimum, integer_schema.maximum) {
|
||||
(Some(min), Some(max)) => format!("<integer> ({} - {})", min, max),
|
||||
|
@ -259,6 +259,8 @@ pub struct StringSchema {
|
||||
pub max_length: Option<usize>,
|
||||
/// 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
|
||||
|
Loading…
Reference in New Issue
Block a user