Debian Codegraph @

tests/integration/skip.rs

raw symbols SCIP
1 use crate::prelude::*;
2
3 #[derive(JsonSchema, Deserialize, Serialize)]
4 #[serde(deny_unknown_fields)]
5 struct Struct {
6 #[serde(skip)]
7 _skipped: bool,
8 included: bool,
9 }
10
11 #[test]
12 fn skip_struct_field() {
13 test!(Struct)
14 .assert_snapshot()
15 .assert_allows_de_roundtrip([json!({ "included": true })])
16 .assert_rejects_de([json!({
17 "_skipped": true,
18 "included": true
19 })])
20 .assert_matches_de_roundtrip(arbitrary_values_except(
21 Value::is_array,
22 "structs with `#derive(Deserialize)` can technically be deserialized from sequences, but that's not intended to be used via JSON, so schemars ignores it",
23 ));
24 }
25
26 #[derive(JsonSchema, Deserialize, Serialize)]
27 pub enum Enum {
28 Included1,
29 #[serde(skip)]
30 _Skipped,
31 Included2,
32 }
33
34 #[test]
35 fn skip_enum_variants() {
36 test!(Enum)
37 .assert_snapshot()
38 .assert_allows_de_roundtrip([json!("Included1"), json!("Included2")])
39 .assert_rejects_de([json!("_Skipped")])
40 .assert_matches_de_roundtrip(arbitrary_values());
41 }