Skip to content

Commit

Permalink
feat(schema): added json schema to support schema on xcm messages (#785)
Browse files Browse the repository at this point in the history
* schemars

* comment

* clean up, aligned version of schema with CosmWasm for now

* Update bounded-collections/src/bounded_vec.rs

Co-authored-by: ordian <[email protected]>

---------

Co-authored-by: ordian <[email protected]>
  • Loading branch information
dzmitry-lahoda and ordian authored Oct 9, 2023
1 parent 6ba5669 commit 97973e5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bounded-collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions bounded-collections/src/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, S>(pub(super) Vec<T>, #[cfg_attr(feature = "serde", serde(skip_serializing))] PhantomData<S>);

/// Create an object through truncation.
Expand Down
2 changes: 2 additions & 0 deletions primitive-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
17 changes: 17 additions & 0 deletions primitive-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit 97973e5

Please sign in to comment.