Skip to main content

ckb_jsonrpc_types/
json_schema.rs

1use crate::{Byte32, Uint32, Uint64, Uint128};
2use schemars::JsonSchema;
3use std::borrow::Cow;
4
5macro_rules! impl_json_schema_for_type {
6    ($type:ty, $inner_ty:ty, $name:expr) => {
7        impl JsonSchema for $type {
8            fn schema_name() -> Cow<'static, str> {
9                Cow::Borrowed($name)
10            }
11            fn json_schema(gn: &mut schemars::SchemaGenerator) -> schemars::Schema {
12                gn.subschema_for::<$inner_ty>()
13            }
14        }
15    };
16}
17
18impl_json_schema_for_type!(Byte32, [u8; 32], "Byte32");
19impl_json_schema_for_type!(Uint32, u32, "Uint32");
20impl_json_schema_for_type!(Uint64, u64, "Uint64");
21impl_json_schema_for_type!(Uint128, u128, "Uint128");
22
23pub fn u256_json_schema(_schemars: &mut schemars::SchemaGenerator) -> schemars::Schema {
24    schemars::json_schema!({
25        "type": "string",
26        "format": "uint256"
27    })
28}
29
30pub fn rational_u256(_schemars: &mut schemars::SchemaGenerator) -> schemars::Schema {
31    schemars::json_schema!({
32        "type": "string",
33        "format": "rational_u256"
34    })
35}