Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(schema): added json schema to support schema on xcm messages #785

Merged
merged 4 commits into from
Oct 9, 2023
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: 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