Debian Codegraph @

tests/integration/unset.rs

raw symbols SCIP
1 use crate::prelude::*;
2
3 #[derive(Default, Deserialize, Serialize, JsonSchema)]
4 #[serde(from = "FlatStruct", rename_all = "kebab-case")]
5 #[schemars(!from)]
6 pub struct Struct {
7 #[serde(flatten)]
8 inner: Inner,
9 }
10
11 #[derive(Default, Deserialize, Serialize, JsonSchema)]
12 pub struct Inner {
13 /// Documentation for field
14 pub field: String,
15 }
16
17 #[derive(Deserialize)]
18 pub struct FlatStruct {
19 pub field: String,
20 }
21
22 impl From<FlatStruct> for Struct {
23 fn from(value: FlatStruct) -> Self {
24 Self {
25 inner: Inner { field: value.field },
26 }
27 }
28 }
29
30 #[test]
31 fn unset_attributes() {
32 test!(Struct)
33 .assert_snapshot()
34 .assert_allows_ser_roundtrip_default()
35 .assert_matches_de_roundtrip(arbitrary_values_except(
36 Value::is_array,
37 "structs with `#derive(Deserialize)` can technically be deserialized from sequences, but that's not intended to be used via JSON, so schemars ignores it",
38 ));
39 }