Skip to content

Commit

Permalink
make schemars an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
itegulov committed Jun 15, 2022
1 parent a2f7b1d commit bc59ec3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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"]
1 change: 1 addition & 0 deletions near-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,6 @@ pub use serde;
#[doc(hidden)]
pub use serde_json;

#[cfg(feature = "unstable")]
#[doc(hidden)]
pub use schemars;
7 changes: 4 additions & 3 deletions near-sdk/src/promise.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use borsh::BorshSchema;
use schemars::JsonSchema;
use std::cell::RefCell;
use std::collections::HashMap;
use std::io::{Error, Write};
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -543,7 +543,8 @@ impl<T: borsh::BorshSerialize> borsh::BorshSerialize for PromiseOrValue<T> {
}
}

impl<T: JsonSchema> JsonSchema for PromiseOrValue<T> {
#[cfg(feature = "unstable")]
impl<T: schemars::JsonSchema> schemars::JsonSchema for PromiseOrValue<T> {
fn schema_name() -> String {
format!("PromiseOrValue{}", T::schema_name())
}
Expand Down
14 changes: 2 additions & 12 deletions near-sdk/src/types/account_id.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bc59ec3

Please sign in to comment.