Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}", <T as 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 {}", <T as Type>::RawElementValueType::name()).as_str()));
},
MetaSchemaRef::Reference(s) => {
panic!("expected Inline schema, got Reference: {s}");
Expand All @@ -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 {}", <PoemSmallVec::<u32, 4> as Type>::RawElementValueType::name())));
let elem_type_name = <PoemSmallVec::<u32, 4> 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}");
Expand Down
7 changes: 6 additions & 1 deletion src/smallvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ impl<T: Type, const SIZE: usize> Type for PoemSmallVec<T, SIZE> {
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))
}

Expand Down
7 changes: 6 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ pub(crate) fn fixed_capacity_schema_ref<T: Type, const SIZE: usize>() -> 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()));
Copy link

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaking a new Box on every call can lead to unbounded memory growth; consider caching the leaked &str (e.g., using OnceCell or lazy_static) so the description is allocated only once per schema.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think poem only calls this once to build the openapi schema ? wouldn't this method already be pretty expensive to call over and over


MetaSchemaRef::Inline(Box::new(schema))
}
Loading