Don't include number format in schema for value
Guessing the format for serde_json::Number can be very misleading, so let's not
This commit is contained in:
parent
9b71b428cb
commit
04996efeb3
6 changed files with 109 additions and 42 deletions
49
schemars/tests/expected/from_json_value.json
Normal file
49
schemars/tests/expected/from_json_value.json
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"examples": [
|
||||
{
|
||||
"bool": true,
|
||||
"minusOne": -1,
|
||||
"null": null,
|
||||
"object": {
|
||||
"array": [
|
||||
"foo",
|
||||
"bar"
|
||||
]
|
||||
},
|
||||
"one": 1,
|
||||
"zero": 0,
|
||||
"zeroPointZero": 0.0
|
||||
}
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bool": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"minusOne": {
|
||||
"type": "integer"
|
||||
},
|
||||
"null": true,
|
||||
"object": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"array": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"one": {
|
||||
"type": "integer"
|
||||
},
|
||||
"zero": {
|
||||
"type": "integer"
|
||||
},
|
||||
"zeroPointZero": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,8 +26,7 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"myInt": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
"type": "integer"
|
||||
},
|
||||
"myBool": {
|
||||
"type": "boolean"
|
||||
|
@ -39,8 +38,7 @@
|
|||
"my_map": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"my_vec": {
|
||||
|
@ -66,9 +64,7 @@
|
|||
"minLength": 1
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "uint8",
|
||||
"minimum": 0.0
|
||||
"type": "integer"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"myInt": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
"type": "integer"
|
||||
},
|
||||
"myBool": {
|
||||
"type": "boolean"
|
||||
|
@ -39,8 +38,7 @@
|
|||
"my_map": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"my_vec": {
|
||||
|
@ -66,9 +64,7 @@
|
|||
"minLength": 1
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "uint8",
|
||||
"minimum": 0.0
|
||||
"type": "integer"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"myInt": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
"type": "integer"
|
||||
},
|
||||
"myBool": {
|
||||
"type": "boolean"
|
||||
|
@ -19,8 +18,7 @@
|
|||
"my_map": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"my_vec": {
|
||||
|
@ -46,9 +44,7 @@
|
|||
"minLength": 1
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"format": "uint8",
|
||||
"minimum": 0.0
|
||||
"type": "integer"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
mod util;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use schemars::gen::SchemaSettings;
|
||||
use schemars::gen::{SchemaGenerator, SchemaSettings};
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use util::*;
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -75,3 +74,21 @@ fn schema_from_value_matches_openapi3() -> TestResult {
|
|||
|
||||
test_schema(&actual, "from_value_openapi3")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schema_from_json_value() -> TestResult {
|
||||
let gen = SchemaGenerator::default();
|
||||
let actual = gen.into_root_schema_for_value(&serde_json::json!({
|
||||
"zero": 0,
|
||||
"one": 1,
|
||||
"minusOne": -1,
|
||||
"zeroPointZero": 0.0,
|
||||
"bool": true,
|
||||
"null": null,
|
||||
"object": {
|
||||
"array": ["foo", "bar"]
|
||||
},
|
||||
}))?;
|
||||
|
||||
test_schema(&actual, "from_json_value")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue