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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! JSON Schema helper functions to suppress non-standard `format` keywords
//! generated by schemars for unsigned integer types.
//!
//! # Why this module exists — READ BEFORE ADDING `uN`/`Option<uN>` FIELDS
//!
//! schemars 1.x emits a non-standard `"format": "uintN"` keyword for every
//! unsigned integer type (`uint8`, `uint16`, `uint32`, `uint64`, `uint`).
//! None of these are part of the JSON Schema spec. Validators (jsonschema,
//! AJV, …) log a warning like
//!
//! ```text
//! unknown format "uint16" ignored in schema at path "#/properties/vid"
//! ```
//!
//! and then silently drop the constraint. This is the source of the
//! `logs/unknown format "uintN" ignored` warnings this crate has shipped
//! multiple times.
//!
//! **Rule:** every `uN` / `Option<uN>` field on a struct that derives
//! [`schemars::JsonSchema`] MUST be annotated with
//! `#[schemars(schema_with = "crate::schema_helpers::uint_schema")]`
//! (or `option_uint_schema` for `Option<uN>`).
//!
//! **Corollary:** if such a field is also omitted from serialized output via
//! `#[serde(skip_serializing_if = "Option::is_none")]`, it MUST additionally
//! carry `#[serde(default)]`: schemars 1.2.2 does not see through
//! `schema_with` to the `Option` type, so without `default` the field lands
//! in the schema's `required` array while serialization still omits it. The
//! default evaluates to `None` (skipped), so no `"default"` key is emitted
//! into the schema. See `src/serial/port_info.rs` (vid/pid/interface) and the
//! `port_info_optional_usb_fields_not_required` regression test.
//!
//! **Guards:** `serial::schema` (per-type schema scan, covers all known public
//! `JsonSchema` types) and `tools::tests::tool_schemas_have_no_nonstandard_uint_formats`
//! (tool `outputSchema` string scan, now covers uint8/uint16/uint32/uint64).
//! Do not delete these tests; extend the type list when adding new
//! `JsonSchema`-deriving structs with unsigned integer fields.
use ;
use crate;
/// Schema for unsigned integer fields without the non-standard `format` keyword.
/// Emits `{"type": "integer", "minimum": 0}`.
/// Schema for `Option<usize>`/`Option<u32>`/`Option<u64>` without the
/// non-standard `format` keyword.
/// Emits `{"anyOf": [{"type": "null"}, {"type": "integer", "minimum": 0}]}`.
/// Schema for `no_new_rx_timeout_ms`: rejects 0 (must be > 0) or null (disabled).
/// Schema for `Vec<u8>` byte array fields, suppressing the non-standard
/// `format: uint8` on the array items that schemars would otherwise emit.