Implement JsonSchema for nonzero signed ints

This commit is contained in:
Graham Esau 2019-10-29 21:40:50 +00:00
parent a35b469475
commit 50f00be97b
6 changed files with 92 additions and 2 deletions

View file

@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MyStruct",
"type": "object",
"required": [
"nonzero_signed",
"nonzero_unsigned",
"signed",
"unsigned"
],
"properties": {
"nonzero_signed": {
"type": "integer",
"format": "int32",
"not": {
"const": 0
}
},
"nonzero_unsigned": {
"type": "integer",
"format": "uint32",
"minimum": 1.0
},
"signed": {
"type": "integer",
"format": "int32"
},
"unsigned": {
"type": "integer",
"format": "uint32"
}
}
}

View file

@ -0,0 +1,21 @@
mod util;
#[cfg(num_nonzero_signed)]
mod nonzero_ints {
use super::*;
use schemars::JsonSchema;
use util::*;
#[derive(Debug, JsonSchema)]
struct MyStruct {
unsigned: u32,
nonzero_unsigned: std::num::NonZeroU32,
signed: i32,
nonzero_signed: std::num::NonZeroI32,
}
#[test]
fn nonzero_ints() -> TestResult {
test_default_generated_schema::<MyStruct>("nonzero_ints")
}
}