ckb_jsonrpc_types/
json_schema.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::{Byte32, Uint128, Uint32, Uint64};
use schemars::JsonSchema;

macro_rules! impl_json_schema_for_type {
    ($type:ty, $inner_ty:ty, $name:expr) => {
        impl JsonSchema for $type {
            fn schema_name() -> String {
                String::from($name)
            }
            fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
                gen.subschema_for::<$inner_ty>().into_object().into()
            }
        }
    };
}

impl_json_schema_for_type!(Byte32, [u8; 32], "Byte32");
impl_json_schema_for_type!(Uint32, u32, "Uint32");
impl_json_schema_for_type!(Uint64, u64, "Uint64");
impl_json_schema_for_type!(Uint128, u128, "Uint128");

pub fn u256_json_schema(
    _schemars: &mut schemars::gen::SchemaGenerator,
) -> schemars::schema::Schema {
    schemars::schema::SchemaObject {
        instance_type: Some(schemars::schema::InstanceType::String.into()),
        format: Some("uint256".to_string()),
        ..Default::default()
    }
    .into()
}

pub fn rational_u256(_schemars: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
    schemars::schema::SchemaObject {
        instance_type: Some(schemars::schema::InstanceType::String.into()),
        format: Some("rational_u256".to_string()),
        ..Default::default()
    }
    .into()
}