From bc59ec3d30633686fd419f83daf34b85e7b462d8 Mon Sep 17 00:00:00 2001 From: Daniyar Itegulov Date: Wed, 15 Jun 2022 15:05:41 +1000 Subject: [PATCH] make schemars an optional dependency --- near-sdk/Cargo.toml | 4 ++-- near-sdk/src/lib.rs | 1 + near-sdk/src/promise.rs | 7 ++++--- near-sdk/src/types/account_id.rs | 14 ++------------ 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/near-sdk/Cargo.toml b/near-sdk/Cargo.toml index 5e9b21027..dd60e746f 100644 --- a/near-sdk/Cargo.toml +++ b/near-sdk/Cargo.toml @@ -25,7 +25,7 @@ near-sys = { path = "../sys", version = "0.2" } base64 = "0.13" borsh = { version = "0.9", features = ["const-generics"] } bs58 = "0.4" -schemars = "0.8.8" +schemars = { version = "0.8.8", optional = true } # Export dependencies for contracts wee_alloc = { version = "0.4.5", default-features = false, optional = true } @@ -50,4 +50,4 @@ hex = { version = "0.4.3", features = ["serde"] } [features] default = ["wee_alloc"] expensive-debug = [] -unstable = ["once_cell", "near-sdk-macros/unstable"] +unstable = ["once_cell", "schemars", "near-sdk-macros/unstable"] diff --git a/near-sdk/src/lib.rs b/near-sdk/src/lib.rs index 49eedc4e4..5d2ab8131 100644 --- a/near-sdk/src/lib.rs +++ b/near-sdk/src/lib.rs @@ -74,5 +74,6 @@ pub use serde; #[doc(hidden)] pub use serde_json; +#[cfg(feature = "unstable")] #[doc(hidden)] pub use schemars; diff --git a/near-sdk/src/promise.rs b/near-sdk/src/promise.rs index ec75c4b26..f75438698 100644 --- a/near-sdk/src/promise.rs +++ b/near-sdk/src/promise.rs @@ -1,5 +1,4 @@ use borsh::BorshSchema; -use schemars::JsonSchema; use std::cell::RefCell; use std::collections::HashMap; use std::io::{Error, Write}; @@ -475,7 +474,8 @@ impl borsh::BorshSerialize for Promise { } } -impl JsonSchema for Promise { +#[cfg(feature = "unstable")] +impl schemars::JsonSchema for Promise { fn schema_name() -> String { "Promise".to_string() } @@ -543,7 +543,8 @@ impl borsh::BorshSerialize for PromiseOrValue { } } -impl JsonSchema for PromiseOrValue { +#[cfg(feature = "unstable")] +impl schemars::JsonSchema for PromiseOrValue { fn schema_name() -> String { format!("PromiseOrValue{}", T::schema_name()) } diff --git a/near-sdk/src/types/account_id.rs b/near-sdk/src/types/account_id.rs index f89ecdab2..ad14f73f6 100644 --- a/near-sdk/src/types/account_id.rs +++ b/near-sdk/src/types/account_id.rs @@ -1,5 +1,4 @@ use borsh::{maybestd::io, BorshDeserialize, BorshSchema, BorshSerialize}; -use schemars::JsonSchema; use serde::{de, Deserialize, Serialize}; use std::convert::TryFrom; use std::fmt; @@ -35,18 +34,9 @@ use crate::env::is_valid_account_id; /// /// [`FromStr`]: std::str::FromStr #[derive( - Debug, - Clone, - PartialEq, - PartialOrd, - Ord, - Eq, - BorshSerialize, - Serialize, - Hash, - BorshSchema, - JsonSchema, + Debug, Clone, PartialEq, PartialOrd, Ord, Eq, BorshSerialize, Serialize, Hash, BorshSchema, )] +#[cfg_attr(feature = "serde_support", derive(schemars::JsonSchema))] pub struct AccountId(String); impl AccountId {