alloy_primitives/bits/
schemars.rs1use alloc::borrow::Cow;
2
3use super::FixedBytes;
4use ::schemars::*;
5
6impl<const N: usize> JsonSchema for FixedBytes<N> {
7 fn schema_name() -> Cow<'static, str> {
8 Cow::Borrowed("FixedBytes")
9 }
10
11 fn json_schema(_: &mut SchemaGenerator) -> Schema {
12 json_schema!({
13 "description": "hexadecimal string",
14 "anyOf": [
15 {
16 "type": "string",
17 "minLength": N * 2,
18 "maxLength": N * 2,
19 "pattern": "^[0-9a-fA-F]*$"
20 },
21 {
22 "type": "string",
23 "minLength": 2 + N * 2,
24 "maxLength": 2 + N * 2,
25 "pattern": "^0x[0-9a-fA-F]*$"
26 },
27 ]
28 })
29 }
30
31 fn schema_id() -> Cow<'static, str> {
32 Cow::Borrowed(concat!(module_path!(), "::FixedBytes"))
33 }
34}