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

remove support for generating a json schema with schemars #84

Merged
merged 2 commits into from
Dec 23, 2024
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
4 changes: 0 additions & 4 deletions crates/sui-sdk-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ rustdoc-args = [
[features]
default = []
serde = ["dep:serde", "dep:serde_derive", "dep:serde_with", "dep:bcs", "dep:serde_json", "roaring/std"]
schemars = ["serde", "dep:schemars", "dep:serde_json"]
rand = ["dep:rand_core"]
hash = ["dep:blake2"]
proptest = ["dep:proptest", "dep:test-strategy", "serde"]
Expand All @@ -44,9 +43,6 @@ serde_with = { version = "3.9", default-features = false, features = ["alloc"],
bcs = { version = "0.1.6", optional = true }
serde_json = { version = "1.0.128", optional = true }

# JsonSchema definitions for types, useful for generating an OpenAPI Specificaiton.
schemars = { version = "0.8.21", optional = true }

# RNG support
rand_core = { version = "0.6.4", optional = true }

Expand Down
33 changes: 0 additions & 33 deletions crates/sui-sdk-types/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,6 @@ impl std::fmt::Display for AddressParseError {

impl std::error::Error for AddressParseError {}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for Address {
fn schema_name() -> String {
"Address".to_owned()
}

fn json_schema(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
use schemars::schema::InstanceType;
use schemars::schema::Metadata;
use schemars::schema::SchemaObject;
use schemars::schema::StringValidation;

let hex_length = Address::LENGTH * 2;
SchemaObject {
metadata: Some(Box::new(Metadata {
title: Some(Self::schema_name()),
description: Some("A 32-byte Sui address, encoded as a hex string.".to_owned()),
examples: vec![serde_json::to_value(Address::TWO).unwrap()],
..Default::default()
})),
instance_type: Some(InstanceType::String.into()),
format: Some("hex".to_owned()),
string: Some(Box::new(StringValidation {
max_length: Some((hex_length + 2) as u32),
min_length: None,
pattern: Some(format!("0x[a-z0-9]{{1,{hex_length}}}")),
})),
..Default::default()
}
.into()
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
26 changes: 0 additions & 26 deletions crates/sui-sdk-types/src/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ pub type StakeUnit = u64;
pub type ProtocolVersion = u64;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "schemars",
derive(schemars::JsonSchema),
schemars(tag = "type", rename_all = "snake_case")
)]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub enum CheckpointCommitment {
EcmhLiveObjectSet { digest: Digest },
Expand All @@ -35,7 +30,6 @@ pub enum CheckpointCommitment {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct EndOfEpochData {
/// next_epoch_committee is `Some` if and only if the current checkpoint is
Expand All @@ -50,24 +44,19 @@ pub struct EndOfEpochData {
/// The protocol version that is in effect during the epoch that starts immediately after this
/// checkpoint.
#[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub next_epoch_protocol_version: ProtocolVersion,

/// Commitments to epoch specific state (e.g. live object set)
pub epoch_commitments: Vec<CheckpointCommitment>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointSummary {
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub epoch: EpochId,
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub sequence_number: CheckpointSequenceNumber,
/// Total number of transactions committed since genesis, including those in this
/// checkpoint.
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub network_total_transactions: u64,
pub content_digest: CheckpointContentsDigest,
pub previous_digest: Option<CheckpointDigest>,
Expand All @@ -78,15 +67,10 @@ pub struct CheckpointSummary {
/// Timestamp of the checkpoint - number of milliseconds from the Unix epoch
/// Checkpoint timestamps are monotonic, but not strongly monotonic - subsequent
/// checkpoints can have same timestamp if they originate from the same underlining consensus commit
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
pub timestamp_ms: CheckpointTimestamp,

/// Commitments to checkpoint-specific state (e.g. txns in checkpoint, objects read/written in
/// checkpoint).
#[cfg_attr(
feature = "schemars",
schemars(with = "Option<Vec<CheckpointCommitment>>")
)]
pub checkpoint_commitments: Vec<CheckpointCommitment>,

/// Present only on the final checkpoint of the epoch.
Expand All @@ -96,10 +80,6 @@ pub struct CheckpointSummary {
/// code. Therefore, in order to allow extensions to be added to CheckpointSummary, we allow
/// opaque data to be added to checkpoints which can be deserialized based on the current
/// protocol version.
#[cfg_attr(
feature = "schemars",
schemars(with = "Option<crate::_schemars::Base64>")
)]
pub version_specific_data: Vec<u8>,
}

Expand All @@ -108,15 +88,13 @@ pub struct CheckpointSummary {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct SignedCheckpointSummary {
pub checkpoint: CheckpointSummary,
pub signature: ValidatorAggregatedSignature,
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointContents(
#[cfg_attr(feature = "proptest", any(proptest::collection::size_range(0..=2).lift()))]
Expand All @@ -142,7 +120,6 @@ impl CheckpointContents {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointTransactionInfo {
pub transaction: TransactionDigest,
Expand All @@ -156,7 +133,6 @@ pub struct CheckpointTransactionInfo {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointData {
pub checkpoint_summary: SignedCheckpointSummary,
Expand All @@ -170,15 +146,13 @@ pub struct CheckpointData {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct CheckpointTransaction {
/// The input Transaction
#[cfg_attr(
feature = "serde",
serde(with = "::serde_with::As::<crate::_serde::SignedTransactionWithIntentMessage>")
)]
#[cfg_attr(feature = "schemars", schemars(with = "SignedTransaction"))]
pub transaction: SignedTransaction,
/// The effects produced by executing this transaction
pub effects: TransactionEffects,
Expand Down
4 changes: 0 additions & 4 deletions crates/sui-sdk-types/src/crypto/bls12381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Bls12381PublicKey(
#[cfg_attr(
Expand All @@ -14,7 +13,6 @@ pub struct Bls12381PublicKey(
with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array96, [::serde_with::Same; 96]>>"
)
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down Expand Up @@ -106,7 +104,6 @@ impl std::fmt::Debug for Bls12381PublicKey {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Bls12381Signature(
#[cfg_attr(
Expand All @@ -115,7 +112,6 @@ pub struct Bls12381Signature(
with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array48, [::serde_with::Same; 48]>>"
)
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down
4 changes: 0 additions & 4 deletions crates/sui-sdk-types/src/crypto/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Ed25519PublicKey(
#[cfg_attr(
feature = "serde",
serde(with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array32>>")
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down Expand Up @@ -104,7 +102,6 @@ impl std::fmt::Debug for Ed25519PublicKey {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Ed25519Signature(
#[cfg_attr(
Expand All @@ -113,7 +110,6 @@ pub struct Ed25519Signature(
with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array64, [::serde_with::Same; 64]>>"
)
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down
34 changes: 0 additions & 34 deletions crates/sui-sdk-types/src/crypto/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub enum MultisigMemberPublicKey {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MultisigMember {
public_key: MultisigMemberPublicKey,
Expand All @@ -56,7 +55,6 @@ impl MultisigMember {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MultisigCommittee {
/// A list of committee members and their corresponding weight.
Expand Down Expand Up @@ -114,7 +112,6 @@ impl MultisigCommittee {

/// The struct that contains signatures and public keys necessary for authenticating a Multisig.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct MultisigAggregatedSignature {
/// The plain signature encoded with signature scheme.
Expand All @@ -126,13 +123,6 @@ pub struct MultisigAggregatedSignature {
bitmap: BitmapUnit,
/// Legacy encoding for the bitmap.
//TODO implement a strategy for legacy bitmap
#[cfg_attr(
feature = "schemars",
schemars(
skip_serializing_if = "Option::is_none",
with = "Option<crate::_schemars::Base64>",
)
)]
#[cfg_attr(feature = "proptest", strategy(proptest::strategy::Just(None)))]
legacy_bitmap: Option<roaring::RoaringBitmap>,
/// The public key encoded with each public key with its signature scheme used along with the corresponding weight.
Expand Down Expand Up @@ -534,25 +524,13 @@ mod serialization {
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(tag = "scheme", rename_all = "lowercase")]
#[serde(rename = "MultisigMemberPublicKey")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
enum ReadableMemberPublicKey {
Ed25519 { public_key: Ed25519PublicKey },
Secp256k1 { public_key: Secp256k1PublicKey },
Secp256r1 { public_key: Secp256r1PublicKey },
ZkLogin(ZkLoginPublicIdentifier),
}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for MultisigMemberPublicKey {
fn schema_name() -> String {
ReadableMemberPublicKey::schema_name()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
ReadableMemberPublicKey::json_schema(gen)
}
}

impl Serialize for MultisigMemberPublicKey {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down Expand Up @@ -640,25 +618,13 @@ mod serialization {
#[derive(serde_derive::Serialize, serde_derive::Deserialize)]
#[serde(tag = "scheme", rename_all = "lowercase")]
#[serde(rename = "MultisigMemberSignature")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
enum ReadableMemberSignature {
Ed25519 { signature: Ed25519Signature },
Secp256k1 { signature: Secp256k1Signature },
Secp256r1 { signature: Secp256r1Signature },
ZkLogin(Box<ZkLoginAuthenticator>),
}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for MultisigMemberSignature {
fn schema_name() -> String {
ReadableMemberSignature::schema_name()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
ReadableMemberSignature::json_schema(gen)
}
}

impl Serialize for MultisigMemberSignature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
12 changes: 0 additions & 12 deletions crates/sui-sdk-types/src/crypto/passkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,12 @@ mod serialization {

#[derive(serde::Deserialize)]
#[serde(rename = "PasskeyAuthenticator")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
struct Authenticator {
authenticator_data: Vec<u8>,
client_data_json: String,
signature: SimpleSignature,
}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for PasskeyAuthenticator {
fn schema_name() -> String {
Authenticator::schema_name()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
Authenticator::json_schema(gen)
}
}

impl Serialize for PasskeyAuthenticator {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
4 changes: 0 additions & 4 deletions crates/sui-sdk-types/src/crypto/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Secp256k1PublicKey(
#[cfg_attr(
Expand All @@ -14,7 +13,6 @@ pub struct Secp256k1PublicKey(
with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array33, [::serde_with::Same; 33]>>"
)
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down Expand Up @@ -106,7 +104,6 @@ impl std::fmt::Debug for Secp256k1PublicKey {
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
pub struct Secp256k1Signature(
#[cfg_attr(
Expand All @@ -115,7 +112,6 @@ pub struct Secp256k1Signature(
with = "::serde_with::As::<::serde_with::IfIsHumanReadable<super::Base64Array64, [::serde_with::Same; 64]>>"
)
)]
#[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
[u8; Self::LENGTH],
);

Expand Down
Loading
Loading