From c8e38d6a5a6fbba233fb9cce7409b10c89aab593 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 23 Mar 2023 16:06:56 +1100 Subject: [PATCH] hashes: Implement JsonSchema for sha256t::Hash The derived implementation of `JsonSchema` recently stopped working as described here: https://github.com/rust-bitcoin/rust-bitcoin/pull/1696#issuecomment-1458670415 Implement the suggestion. --- hashes/src/sha256t.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hashes/src/sha256t.rs b/hashes/src/sha256t.rs index 95c23e19..c45756c0 100644 --- a/hashes/src/sha256t.rs +++ b/hashes/src/sha256t.rs @@ -31,16 +31,17 @@ pub trait Tag { } /// Output of the SHA256t hash function. -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[repr(transparent)] -pub struct Hash( - #[cfg_attr( - feature = "schemars", - schemars(schema_with = "crate::util::json_hex_string::len_32") - )] - [u8; 32], - #[cfg_attr(feature = "schemars", schemars(skip))] PhantomData, -); +pub struct Hash([u8; 32], PhantomData); + +#[cfg(feature = "schemars")] +impl schemars::JsonSchema for Hash { + fn schema_name() -> String { "Hash".to_owned() } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + crate::util::json_hex_string::len_32(gen) + } +} impl Hash { fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, Default::default()) }