-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port inline_subschemas tests to new integration test style
- Loading branch information
Showing
7 changed files
with
155 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::prelude::*; | ||
use schemars::generate::SchemaSettings; | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize, Default)] | ||
struct MyJob { | ||
spec: MyJobSpec, | ||
} | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize, Default)] | ||
struct MyJobSpec { | ||
replicas: u32, | ||
} | ||
|
||
#[test] | ||
fn struct_normal() { | ||
let settings = SchemaSettings::default().with(|s| s.inline_subschemas = true); | ||
test!(MyJob, settings) | ||
.assert_snapshot() | ||
.assert_allows_ser_roundtrip_default() | ||
.assert_matches_de_roundtrip(arbitrary_values()); | ||
} | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize)] | ||
struct RecursiveOuter { | ||
direct: Option<Box<RecursiveOuter>>, | ||
indirect: Option<Box<RecursiveInner>>, | ||
} | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize)] | ||
struct RecursiveInner { | ||
recursive: RecursiveOuter, | ||
} | ||
|
||
#[test] | ||
fn struct_recursive() { | ||
let settings = SchemaSettings::default().with(|s| s.inline_subschemas = true); | ||
test!(RecursiveOuter, settings) | ||
.assert_snapshot() | ||
.assert_allows_ser_roundtrip([ | ||
RecursiveOuter { | ||
direct: None, | ||
indirect: None, | ||
}, | ||
RecursiveOuter { | ||
direct: Some(Box::new(RecursiveOuter { | ||
direct: None, | ||
indirect: None, | ||
})), | ||
indirect: Some(Box::new(RecursiveInner { | ||
recursive: RecursiveOuter { | ||
direct: Some(Box::new(RecursiveOuter { | ||
direct: None, | ||
indirect: None, | ||
})), | ||
indirect: None, | ||
}, | ||
})), | ||
}, | ||
]) | ||
.assert_matches_de_roundtrip(arbitrary_values()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
...egration/snapshots/schemars/tests/integration/inline_subschemas.rs~struct_normal.ser.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "MyJob", | ||
"type": "object", | ||
"properties": { | ||
"spec": { | ||
"type": "object", | ||
"properties": { | ||
"replicas": { | ||
"type": "integer", | ||
"format": "uint32", | ||
"minimum": 0 | ||
} | ||
}, | ||
"required": [ | ||
"replicas" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"spec" | ||
] | ||
} |
File renamed without changes.
70 changes: 70 additions & 0 deletions
70
...ation/snapshots/schemars/tests/integration/inline_subschemas.rs~struct_recursive.ser.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "RecursiveOuter", | ||
"type": "object", | ||
"properties": { | ||
"direct": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/$defs/RecursiveOuter" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"indirect": { | ||
"type": [ | ||
"object", | ||
"null" | ||
], | ||
"properties": { | ||
"recursive": { | ||
"$ref": "#/$defs/RecursiveOuter" | ||
} | ||
}, | ||
"required": [ | ||
"recursive" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"direct", | ||
"indirect" | ||
], | ||
"$defs": { | ||
"RecursiveOuter": { | ||
"type": "object", | ||
"properties": { | ||
"direct": { | ||
"anyOf": [ | ||
{ | ||
"$ref": "#/$defs/RecursiveOuter" | ||
}, | ||
{ | ||
"type": "null" | ||
} | ||
] | ||
}, | ||
"indirect": { | ||
"type": [ | ||
"object", | ||
"null" | ||
], | ||
"properties": { | ||
"recursive": { | ||
"$ref": "#/$defs/RecursiveOuter" | ||
} | ||
}, | ||
"required": [ | ||
"recursive" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"direct", | ||
"indirect" | ||
] | ||
} | ||
} | ||
} |