Make Option<T> fields optional in generated schemas (#16)
This commit is contained in:
parent
60284fdf93
commit
4ad5000232
14 changed files with 269 additions and 148 deletions
|
@ -19,9 +19,6 @@
|
|||
"properties": {
|
||||
"Complex": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"my_nullable_string"
|
||||
],
|
||||
"properties": {
|
||||
"my_nullable_string": {
|
||||
"title": "A nullable string",
|
||||
|
|
34
schemars/tests/expected/flatten.json
Normal file
34
schemars/tests/expected/flatten.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Flat",
|
||||
"type": "object",
|
||||
"required": [
|
||||
"b",
|
||||
"f",
|
||||
"s",
|
||||
"v"
|
||||
],
|
||||
"properties": {
|
||||
"b": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"f": {
|
||||
"type": "number",
|
||||
"format": "float"
|
||||
},
|
||||
"os": {
|
||||
"default": "",
|
||||
"type": "string"
|
||||
},
|
||||
"s": {
|
||||
"type": "string"
|
||||
},
|
||||
"v": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,12 @@
|
|||
"bar": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"baz": {
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"foo": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
},
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 2
|
||||
"maxItems": 3,
|
||||
"minItems": 3
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
mod util;
|
||||
use pretty_assertions::assert_eq;
|
||||
use schemars::{schema_for, JsonSchema};
|
||||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
struct Flat {
|
||||
|
@ -43,8 +43,11 @@ struct Deep4 {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn flatten_schema() {
|
||||
let flat = schema_for!(Flat);
|
||||
let deep = schema_for!(Deep1);
|
||||
assert_eq!(flat, deep);
|
||||
fn test_flat_schema() -> TestResult {
|
||||
test_default_generated_schema::<Flat>("flatten")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flattened_schema() -> TestResult {
|
||||
test_default_generated_schema::<Deep1>("flatten")
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use util::*;
|
|||
pub struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
baz: Option<String>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -14,7 +15,7 @@ fn struct_normal() -> TestResult {
|
|||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Tuple(i32, bool);
|
||||
pub struct Tuple(i32, bool, Option<String>);
|
||||
|
||||
#[test]
|
||||
fn struct_tuple() -> TestResult {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue