-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port
skip
tests to new integration test style
- Loading branch information
Showing
9 changed files
with
77 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,41 @@ | ||
use crate::prelude::*; | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
struct Struct { | ||
#[serde(skip)] | ||
_skipped: bool, | ||
included: bool, | ||
} | ||
|
||
#[test] | ||
fn skip_struct_field() { | ||
test!(Struct) | ||
.assert_snapshot() | ||
.assert_allows_de_roundtrip([json!({ "included": true })]) | ||
.assert_rejects_de([json!({ | ||
"_skipped": true, | ||
"included": true | ||
})]) | ||
.assert_matches_de_roundtrip(arbitrary_values_except( | ||
Value::is_array, | ||
"structs with `#derive(Deserialize)` can technically be deserialized from sequences, but that's not intended to be used via JSON, so schemars ignores it", | ||
)); | ||
} | ||
|
||
#[derive(JsonSchema, Deserialize, Serialize)] | ||
pub enum Enum { | ||
Included1, | ||
#[serde(skip)] | ||
_Skipped, | ||
Included2, | ||
} | ||
|
||
#[test] | ||
fn skip_enum_variants() { | ||
test!(Enum) | ||
.assert_snapshot() | ||
.assert_allows_de_roundtrip([json!("Included1"), json!("Included2")]) | ||
.assert_rejects_de([json!("_Skipped")]) | ||
.assert_matches_de_roundtrip(arbitrary_values()); | ||
} |
9 changes: 9 additions & 0 deletions
9
...tests/integration/snapshots/schemars/tests/integration/skip.rs~skip_enum_variants.de.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,9 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "Enum", | ||
"type": "string", | ||
"enum": [ | ||
"Included1", | ||
"Included2" | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
...ests/integration/snapshots/schemars/tests/integration/skip.rs~skip_enum_variants.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,9 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "Enum", | ||
"type": "string", | ||
"enum": [ | ||
"Included1", | ||
"Included2" | ||
] | ||
} |
11 changes: 3 additions & 8 deletions
11
...rs/tests/expected/skip_struct_fields.json → ...gration/skip.rs~skip_struct_field.de.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 |
---|---|---|
@@ -1,19 +1,14 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "MyStruct", | ||
"title": "Struct", | ||
"type": "object", | ||
"properties": { | ||
"writable": { | ||
"type": "number", | ||
"format": "float", | ||
"writeOnly": true | ||
}, | ||
"included": { | ||
"type": "null" | ||
"type": "boolean" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"writable", | ||
"included" | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
...tests/integration/snapshots/schemars/tests/integration/skip.rs~skip_struct_field.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,14 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"title": "Struct", | ||
"type": "object", | ||
"properties": { | ||
"included": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"included" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.