hashes: Implement JsonSchema for sha256t::Hash<T>

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.
This commit is contained in:
Tobin C. Harding 2023-03-23 16:06:56 +11:00
parent c7f970d8dc
commit c8e38d6a5a
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 10 additions and 9 deletions

View File

@ -31,16 +31,17 @@ pub trait Tag {
} }
/// Output of the SHA256t hash function. /// Output of the SHA256t hash function.
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[repr(transparent)] #[repr(transparent)]
pub struct Hash<T: Tag>( pub struct Hash<T: Tag>([u8; 32], PhantomData<T>);
#[cfg_attr(
feature = "schemars", #[cfg(feature = "schemars")]
schemars(schema_with = "crate::util::json_hex_string::len_32") impl<T: Tag> schemars::JsonSchema for Hash<T> {
)] fn schema_name() -> String { "Hash".to_owned() }
[u8; 32],
#[cfg_attr(feature = "schemars", schemars(skip))] PhantomData<T>, fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
); crate::util::json_hex_string::len_32(gen)
}
}
impl<T: Tag> Hash<T> { impl<T: Tag> Hash<T> {
fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, Default::default()) } fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, Default::default()) }