predawn_schema/impls/
set.rs

1use std::{borrow::Cow, collections::BTreeMap};
2
3use openapiv3::{ArrayType, Schema, SchemaData, SchemaKind, Type};
4
5use crate::ToSchema;
6
7macro_rules! set_impl {
8    ($($desc:tt)+) => {
9        impl $($desc)+
10        where
11            T: ToSchema
12        {
13            fn title() -> Cow<'static, str> {
14                format!("Set<{}>", 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: true,
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
37set_impl!(<T> ToSchema for std::collections::BTreeSet<T>);
38set_impl!(<T, S> ToSchema for std::collections::HashSet<T, S>);
39set_impl!(<T, S> ToSchema for indexmap::set::IndexSet<T, S>);