Skip to main content

schemars/json_schema_impls/
arrayvec07.rs

1use crate::SchemaGenerator;
2use crate::_alloc_prelude::*;
3use crate::{json_schema, JsonSchema, Schema};
4use arrayvec07::{ArrayString, ArrayVec};
5
6// Do not set maxLength on the schema as that describes length in characters, but we only
7// know max length in bytes.
8forward_impl!((<const CAP: usize> JsonSchema for ArrayString<CAP>) => String);
9
10impl<T, const CAP: usize> JsonSchema for ArrayVec<T, CAP>
11where
12    T: JsonSchema,
13{
14    inline_schema!();
15
16    fn schema_name() -> alloc::borrow::Cow<'static, str> {
17        format!("Array_up_to_size_{}_of_{}", CAP, T::schema_name()).into()
18    }
19
20    fn json_schema(generator: &mut SchemaGenerator) -> Schema {
21        json_schema!({
22            "type": "array",
23            "items": generator.subschema_for::<T>(),
24            "maxItems": CAP
25        })
26    }
27}