predawn_schema/impls/
seq.rs

1use std::{borrow::Cow, collections::BTreeMap};
2
3use openapiv3::{ArrayType, Schema, SchemaData, SchemaKind, Type};
4
5use crate::ToSchema;
6
7macro_rules! seq_impl {
8    ($($desc:tt)+) => {
9        impl $($desc)+
10        where
11            T: ToSchema
12        {
13            fn title() -> Cow<'static, str> {
14                format!("List<{}>", T::title()).into()
15            }
16
17            fn schema(schemas: &mut BTreeMap<String, Schema>, schemas_in_progress: &mut Vec<String>) -> Schema {
18                let ty = ArrayType {
19                    items: Some(T::schema_ref_box(schemas, schemas_in_progress)),
20                    min_items: None,
21                    max_items: None,
22                    unique_items: false,
23                };
24
25                Schema {
26                    schema_data: SchemaData {
27                        title: Some(Self::title().into()),
28                        ..Default::default()
29                    },
30                    schema_kind: SchemaKind::Type(Type::Array(ty)),
31                }
32            }
33        }
34    };
35}
36
37seq_impl!(<T> ToSchema for std::collections::BinaryHeap<T>);
38seq_impl!(<T> ToSchema for std::collections::LinkedList<T>);
39seq_impl!(<T> ToSchema for [T]);
40seq_impl!(<T> ToSchema for Vec<T>);
41seq_impl!(<T> ToSchema for std::collections::VecDeque<T>);