Give unsigned int schemas explicit minimum value
This commit is contained in:
parent
50f00be97b
commit
ae716de64a
5 changed files with 47 additions and 15 deletions
|
@ -42,12 +42,6 @@ simple_impl!(i32 => Integer, "int32");
|
|||
simple_impl!(i64 => Integer, "int64");
|
||||
simple_impl!(i128 => Integer, "int128");
|
||||
simple_impl!(isize => Integer, "int");
|
||||
simple_impl!(u8 => Integer, "uint8");
|
||||
simple_impl!(u16 => Integer, "uint16");
|
||||
simple_impl!(u32 => Integer, "uint32");
|
||||
simple_impl!(u64 => Integer, "uint64");
|
||||
simple_impl!(u128 => Integer, "uint128");
|
||||
simple_impl!(usize => Integer, "uint");
|
||||
simple_impl!(() => Null);
|
||||
|
||||
simple_impl!(Path => String);
|
||||
|
@ -61,6 +55,35 @@ simple_impl!(SocketAddr => String);
|
|||
simple_impl!(SocketAddrV4 => String);
|
||||
simple_impl!(SocketAddrV6 => String);
|
||||
|
||||
macro_rules! unsigned_impl {
|
||||
($type:ty => $instance_type:ident, $format:expr) => {
|
||||
impl JsonSchema for $type {
|
||||
no_ref_schema!();
|
||||
|
||||
fn schema_name() -> String {
|
||||
$format.to_owned()
|
||||
}
|
||||
|
||||
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
||||
let mut schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::$instance_type.into()),
|
||||
format: Some($format.to_owned()),
|
||||
..Default::default()
|
||||
};
|
||||
schema.number().minimum = Some(0.0);
|
||||
schema.into()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
unsigned_impl!(u8 => Integer, "uint8");
|
||||
unsigned_impl!(u16 => Integer, "uint16");
|
||||
unsigned_impl!(u32 => Integer, "uint32");
|
||||
unsigned_impl!(u64 => Integer, "uint64");
|
||||
unsigned_impl!(u128 => Integer, "uint128");
|
||||
unsigned_impl!(usize => Integer, "uint");
|
||||
|
||||
impl JsonSchema for char {
|
||||
no_ref_schema!();
|
||||
|
||||
|
|
|
@ -24,11 +24,13 @@
|
|||
"properties": {
|
||||
"nanos": {
|
||||
"type": "integer",
|
||||
"format": "uint32"
|
||||
"format": "uint32",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"secs": {
|
||||
"type": "integer",
|
||||
"format": "uint64"
|
||||
"format": "uint64",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -41,11 +43,13 @@
|
|||
"properties": {
|
||||
"nanos_since_epoch": {
|
||||
"type": "integer",
|
||||
"format": "uint32"
|
||||
"format": "uint32",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"secs_since_epoch": {
|
||||
"type": "integer",
|
||||
"format": "uint64"
|
||||
"format": "uint64",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,8 @@
|
|||
},
|
||||
"unsigned": {
|
||||
"type": "integer",
|
||||
"format": "uint32"
|
||||
"format": "uint32",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,8 @@
|
|||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"format": "uint8"
|
||||
"format": "uint8",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +43,8 @@
|
|||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"format": "uint16"
|
||||
"format": "uint16",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,11 +41,13 @@
|
|||
"properties": {
|
||||
"end": {
|
||||
"type": "integer",
|
||||
"format": "uint"
|
||||
"format": "uint",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"start": {
|
||||
"type": "integer",
|
||||
"format": "uint"
|
||||
"format": "uint",
|
||||
"minimum": 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue