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 2 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.13", 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 = "schema", derive(schemars::JsonSchema))]
dzmitry-lahoda marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 14 additions & 0 deletions build-targets-check.sh
dzmitry-lahoda marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh
# checks combination features are working in real no std and in std other features working for basic types

# uses build instead of check as sometimes some issues are not caught by check
cargo_deep_check() {
cargo build --locked --no-default-features $@
}

cargo_deep_check --target thumbv7em-none-eabi --package primitive-types --features=codec,serde_no_std,byteorder,rustc-hex,codec
cargo_deep_check --target wasm32-unknown-unknown --package primitive-types --features=codec,serde_no_std,byteorder,rustc-hex,codec,num-traits
cargo_deep_check --package primitive-types --features=std,serde,json-schema,byteorder,rustc-hex,codec
cargo_deep_check --target thumbv7em-none-eabi --package bounded-collections
cargo_deep_check --package primitive-types --features=json-schema
cargo_deep_check --target wasm32-unknown-unknown --package bounded-collections
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.13", 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
15 changes: 15 additions & 0 deletions primitive-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ mod serde {
impl_fixed_hash_serde!(H768, 96);
}

#[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
Loading