diff --git a/src/lib.rs b/src/lib.rs index 39e5a82..76efc16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,9 @@ mod tests { // (min/max)-length is supposed to be for strings, but poem uses it for arrays too? assert_eq!(box_meta.min_length, Some(1)); assert_eq!(box_meta.max_length, Some(MAX)); - assert_eq!(box_meta.title, Some(format!("1 to {MAX} items of type {}", ::RawElementValueType::name()))); + let max_str = MAX.to_string(); + let max = max_str.as_str(); + assert_eq!(box_meta.description, Some(format!("1 to {max} items of type {}", ::RawElementValueType::name()).as_str())); }, MetaSchemaRef::Reference(s) => { panic!("expected Inline schema, got Reference: {s}"); @@ -54,7 +56,9 @@ mod tests { assert_eq!(box_meta.max_items, None); assert_eq!(box_meta.min_length, Some(1)); assert_eq!(box_meta.max_length, None); - assert_eq!(box_meta.title, Some(format!("at least 1 item of type {}", as Type>::RawElementValueType::name()))); + let elem_type_name = as Type>::RawElementValueType::name(); + assert_eq!(box_meta.title, Some(format!("Vec<{}>", elem_type_name))); + assert_eq!(box_meta.description, Some(format!("at least 1 item of type {}", elem_type_name)).as_deref()); }, MetaSchemaRef::Reference(s) => { panic!("expected Inline schema, got Reference: {s}"); diff --git a/src/smallvec.rs b/src/smallvec.rs index 94eb076..90085c8 100644 --- a/src/smallvec.rs +++ b/src/smallvec.rs @@ -49,7 +49,12 @@ impl Type for PoemSmallVec { let mut schema = vec_schema.unwrap_inline().clone(); schema.min_items = Some(1); schema.min_length = Some(1); - schema.title = Some(format!("at least 1 item of type {}", T::name())); + schema.title = Some(format!("Vec<{}>", T::name())); + + let desc = ["at least 1 item of type ", &T::name()].concat(); + // this should only get called to build the openapi schema, and not be a repeated cost + schema.description = Some(Box::leak(desc.into_boxed_str())); + MetaSchemaRef::Inline(Box::new(schema)) } diff --git a/src/util.rs b/src/util.rs index 63d157e..607bd1f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -6,6 +6,11 @@ pub(crate) fn fixed_capacity_schema_ref() -> MetaSch schema.min_length = Some(1); schema.min_items = Some(1); schema.max_items = Some(SIZE); - schema.title = Some(format!("1 to {SIZE} items of type {}", T::name())); + schema.title = Some(format!("ArrayVec<{}>", T::name())); + + let desc = format!("1 to {SIZE} items of type {}", T::name()); + // this should only get called to build the openapi schema, and not be a repeated cost + schema.description = Some(Box::leak(desc.into_boxed_str())); + MetaSchemaRef::Inline(Box::new(schema)) }