Adding a `"maximum"` limit to an integer changes the inner Rust type
Opened this issue · 2 comments
jgallagher commented
In the following JSON schema, all three ByteCountN
variants have the same type
and format
, and only differ by maximum
:
ByteCount1
omitsmaximum
ByteCount2
sets itsmaximum
toi64::MAX
ByteCount3
sets itsmaximum
toi64::MAX + 1
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ByteCount1": {
"description": "Byte count to express memory or storage capacity.",
"type": "integer",
"format": "uint64",
"minimum": 0
},
"ByteCount2": {
"description": "Byte count to express memory or storage capacity.",
"type": "integer",
"format": "uint64",
"minimum": 0,
"maximum": 9223372036854775807
},
"ByteCount3": {
"description": "Byte count to express memory or storage capacity.",
"type": "integer",
"format": "uint64",
"minimum": 0,
"maximum": 9223372036854775808
}
}
}
I expected all of these to produce a struct wrapping a u64
, but ByteCount{2,3}
use i64
instead:
% cargo typify bytecount.json && rg 'struct ByteCount' bytecount.rs
48:pub struct ByteCount1(pub u64);
114:pub struct ByteCount2(pub i64);
180:pub struct ByteCount3(pub i64);
ahl commented
Oof.. ByteCount3 seems particularly stupid.