Skip to content

Commit d3a653d

Browse files
authored
Revert "chore: bump schemars to 0.9 (#37)"
This reverts commit 7a3956a.
1 parent 7a3956a commit d3a653d

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1.0.123", default-features = false, features = [
1212
"alloc",
1313
"derive",
1414
], optional = true }
15-
schemars = { version = "0.9", default-features = false, optional = true }
15+
schemars = { version = ">=0.8,<1", default-features = false, optional = true }
1616
thiserror = { version = "2", default-features = false }
1717
proptest = { version = "1.0.0", optional = true }
1818

src/bounded_vec.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,22 +650,29 @@ mod serde_impl {
650650
#[cfg(feature = "schema")]
651651
mod schema {
652652
use super::*;
653-
use alloc::borrow::Cow;
653+
use schemars::schema::{InstanceType, SchemaObject};
654654
use schemars::JsonSchema;
655655

656656
// we cannot use attributes, because the do not work with `const`, only numeric literals supported
657657
impl<T: JsonSchema, const L: usize, const U: usize> JsonSchema for BoundedVec<T, L, U> {
658-
fn schema_name() -> Cow<'static, str> {
659-
alloc::format!("BoundedVec{}Min{}Max{}", T::schema_name(), L, U).into()
658+
fn schema_name() -> alloc::string::String {
659+
alloc::format!("BoundedVec{}Min{}Max{}", T::schema_name(), L, U)
660660
}
661661

662-
fn json_schema(gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
663-
schemars::json_schema!({
664-
"type": "array",
665-
"items": T::json_schema(gen),
666-
"minItems": L as u32,
667-
"maxItems": L as u32
668-
})
662+
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
663+
SchemaObject {
664+
instance_type: Some(InstanceType::Array.into()),
665+
array: Some(alloc::boxed::Box::new(schemars::schema::ArrayValidation {
666+
items: Some(schemars::schema::SingleOrVec::Single(
667+
T::json_schema(gen).into(),
668+
)),
669+
min_items: Some(L as u32),
670+
max_items: Some(U as u32),
671+
..Default::default()
672+
})),
673+
..Default::default()
674+
}
675+
.into()
669676
}
670677
}
671678
}

0 commit comments

Comments
 (0)