api: add type_text to StringSchema

This commit is contained in:
Dietmar Maurer 2021-02-09 09:06:39 +01:00
parent 4efbdd79ef
commit 69bee9524f
2 changed files with 15 additions and 1 deletions

View File

@ -80,7 +80,13 @@ fn test_wrap_text() {
pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String { pub fn get_schema_type_text(schema: &Schema, _style: ParameterDisplayStyle) -> String {
match schema { match schema {
Schema::Null => String::from("<null>"), // should not happen 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::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),

View File

@ -259,6 +259,8 @@ pub struct StringSchema {
pub max_length: Option<usize>, pub max_length: Option<usize>,
/// Optional microformat. /// Optional microformat.
pub format: Option<&'static ApiStringFormat>, pub format: Option<&'static ApiStringFormat>,
/// A text representation of the format/type (used to generate documentation).
pub type_text: Option<&'static str>,
} }
impl StringSchema { impl StringSchema {
@ -269,6 +271,7 @@ impl StringSchema {
min_length: None, min_length: None,
max_length: None, max_length: None,
format: None, format: None,
type_text: None,
} }
} }
@ -282,6 +285,11 @@ impl StringSchema {
self 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 { pub const fn min_length(mut self, min_length: usize) -> Self {
self.min_length = Some(min_length); self.min_length = Some(min_length);
self self