Enable deriving JsonSchema for unit/newtype/tuple structs
This commit is contained in:
parent
07f4f68a02
commit
3f5f7cf0a3
6 changed files with 107 additions and 18 deletions
5
schemars/tests/expected/struct-newtype.json
Normal file
5
schemars/tests/expected/struct-newtype.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Newtype",
|
||||
"type": "integer"
|
||||
}
|
17
schemars/tests/expected/struct-normal.json
Normal file
17
schemars/tests/expected/struct-normal.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Struct",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"foo": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"bar",
|
||||
"foo"
|
||||
]
|
||||
}
|
15
schemars/tests/expected/struct-tuple.json
Normal file
15
schemars/tests/expected/struct-tuple.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Tuple",
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 2
|
||||
}
|
5
schemars/tests/expected/struct-unit.json
Normal file
5
schemars/tests/expected/struct-unit.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Unit",
|
||||
"type": "null"
|
||||
}
|
38
schemars/tests/struct.rs
Normal file
38
schemars/tests/struct.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
mod util;
|
||||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn struct_normal() -> TestResult {
|
||||
test_default_generated_schema::<Struct>("struct-normal")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Tuple(i32, bool);
|
||||
|
||||
#[test]
|
||||
fn struct_tuple() -> TestResult {
|
||||
test_default_generated_schema::<Tuple>("struct-tuple")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Newtype(i32);
|
||||
|
||||
#[test]
|
||||
fn struct_newtype() -> TestResult {
|
||||
test_default_generated_schema::<Newtype>("struct-newtype")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Unit;
|
||||
|
||||
#[test]
|
||||
fn struct_unit() -> TestResult {
|
||||
test_default_generated_schema::<Unit>("struct-unit")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue