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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ serde = { version = "1.0.123", default-features = false, features = [
"alloc",
"derive",
], optional = true }
schemars = { version = ">=0.8,<1", default-features = false, optional = true }
schemars = { version = "0.9", default-features = false, optional = true }
thiserror = { version = "2", default-features = false }
proptest = { version = "1.0.0", optional = true }

Expand Down
27 changes: 10 additions & 17 deletions src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@
}
}

/// Option<BoundedVec<T, _, _>> to Vec<T>

Check warning on line 567 in src/bounded_vec.rs

View workflow job for this annotation

GitHub Actions / Intra-documentation links

unclosed HTML tag `T`
pub trait OptBoundedVecToVec<T> {
/// Option<BoundedVec<T, _, _>> to Vec<T>

Check warning on line 569 in src/bounded_vec.rs

View workflow job for this annotation

GitHub Actions / Intra-documentation links

unclosed HTML tag `T`
fn to_vec(self) -> Vec<T>;
}

Expand Down Expand Up @@ -650,29 +650,22 @@
#[cfg(feature = "schema")]
mod schema {
use super::*;
use schemars::schema::{InstanceType, SchemaObject};
use alloc::borrow::Cow;
use schemars::JsonSchema;

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

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
SchemaObject {
instance_type: Some(InstanceType::Array.into()),
array: Some(alloc::boxed::Box::new(schemars::schema::ArrayValidation {
items: Some(schemars::schema::SingleOrVec::Single(
T::json_schema(gen).into(),
)),
min_items: Some(L as u32),
max_items: Some(U as u32),
..Default::default()
})),
..Default::default()
}
.into()
fn json_schema(gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "array",
"items": T::json_schema(gen),
"minItems": L as u32,
"maxItems": L as u32
})
}
}
}
Expand Down
Loading