Support #[serde(flatten)]ed structs
This commit is contained in:
parent
bd750714a0
commit
54cfd2ba0e
6 changed files with 104 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use schemars::{schema_for, MakeSchema};
|
||||
use schemars::{schema::*, schema_for, MakeSchema};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -32,8 +32,13 @@ struct Deep3 {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "flattening is not yet implemented"]
|
||||
fn flatten_schema() -> Result<(), Box<dyn Error>> {
|
||||
assert_eq!(schema_for!(Flat)?, schema_for!(Deep1)?);
|
||||
let flat = schema_for!(Flat)?;
|
||||
let mut deep = schema_for!(Deep1)?;
|
||||
match deep {
|
||||
Schema::Object(ref mut o) => o.title = Some("Flat".to_owned()),
|
||||
_ => assert!(false, "Schema was not object: {:?}", deep),
|
||||
};
|
||||
assert_eq!(flat, deep);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
]
|
||||
},
|
||||
"SchemaObject": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$id": {
|
||||
"type": "string",
|
||||
|
@ -76,10 +77,6 @@
|
|||
"items": {},
|
||||
"nullable": true
|
||||
},
|
||||
"extensions": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
|
@ -125,8 +122,7 @@
|
|||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"title": {
|
||||
"type": "string",
|
||||
|
@ -146,9 +142,11 @@
|
|||
],
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"SchemaRef": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"type": "string"
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
]
|
||||
},
|
||||
"SchemaObject": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$id": {
|
||||
"anyOf": [
|
||||
|
@ -112,10 +113,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"extensions": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"items": {
|
||||
"anyOf": [
|
||||
{
|
||||
|
@ -156,17 +153,10 @@
|
|||
}
|
||||
},
|
||||
"required": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": {
|
||||
"anyOf": [
|
||||
|
@ -188,9 +178,11 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": true
|
||||
},
|
||||
"SchemaRef": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"$ref": {
|
||||
"type": "string"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue