diff --git a/bounded-collections/Cargo.toml b/bounded-collections/Cargo.toml index 17a9ecb4..fb14da38 100644 --- a/bounded-collections/Cargo.toml +++ b/bounded-collections/Cargo.toml @@ -13,12 +13,14 @@ serde = { version = "1.0.101", default-features = false, optional = true, featur codec = { version = "3.3.0", default-features = false, features = ["max-encoded-len"], package = "parity-scale-codec" } scale-info = { version = ">=1.0, <3", features = ["derive"], default-features = false } log = { version = "0.4.17", default-features = false } +schemars = { version = ">=0.8.12", default-features = true, optional = true } [dev-dependencies] serde_json = "1.0.41" [features] default = ["std"] +json-schema = ["dep:schemars"] std = [ "log/std", "codec/std", diff --git a/bounded-collections/src/bounded_vec.rs b/bounded-collections/src/bounded_vec.rs index cd26afb1..3d426995 100644 --- a/bounded-collections/src/bounded_vec.rs +++ b/bounded-collections/src/bounded_vec.rs @@ -43,6 +43,7 @@ use serde::{ #[cfg_attr(feature = "serde", derive(Serialize), serde(transparent))] #[derive(Encode, scale_info::TypeInfo)] #[scale_info(skip_type_params(S))] +#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))] pub struct BoundedVec(pub(super) Vec, #[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData); /// Create an object through truncation. diff --git a/primitive-types/Cargo.toml b/primitive-types/Cargo.toml index 7aa3d2e9..d642effc 100644 --- a/primitive-types/Cargo.toml +++ b/primitive-types/Cargo.toml @@ -16,6 +16,7 @@ impl-codec = { version = "0.6.0", path = "impls/codec", default-features = false impl-num-traits = { version = "0.1.0", path = "impls/num-traits", default-features = false, optional = true } impl-rlp = { version = "0.3", path = "impls/rlp", default-features = false, optional = true } scale-info-crate = { package = "scale-info", version = ">=0.9, <3", features = ["derive"], default-features = false, optional = true } +schemars = { version = ">=0.8.12", default-features = true, optional = true } [dev-dependencies] num-traits = "0.2" @@ -26,6 +27,7 @@ std = ["uint/std", "fixed-hash/std", "impl-codec?/std"] byteorder = ["fixed-hash/byteorder"] rustc-hex = ["fixed-hash/rustc-hex"] serde = ["std", "impl-serde", "impl-serde/std"] +json-schema = ["dep:schemars"] serde_no_std = ["impl-serde"] codec = ["impl-codec"] scale-info = ["codec", "scale-info-crate"] diff --git a/primitive-types/src/lib.rs b/primitive-types/src/lib.rs index dd372a9e..d80a312f 100644 --- a/primitive-types/src/lib.rs +++ b/primitive-types/src/lib.rs @@ -105,6 +105,23 @@ mod serde { impl_fixed_hash_serde!(H768, 96); } +// true that no need std, but need to do no_std alloc than, so simplified for now +// also no macro, but easy to create +#[cfg(all(feature = "std", feature = "json-schema"))] +mod json_schema { + use super::*; + + impl schemars::JsonSchema for H160 { + fn schema_name() -> String { + "0xPrefixedHexString".to_string() + } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + String::json_schema(gen) + } + } +} + #[cfg(feature = "impl-codec")] mod codec { use super::*;