1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) 2018 The openrtb-rust authors
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::category::Category;
use super::publisher::Publisher;
use serde_utils;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct App {
    pub id: String,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub bundle: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub domain: Option<String>,

    #[serde(rename = "storeurl", skip_serializing_if = "Option::is_none")]
    pub store_url: Option<String>,

    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub cat: Vec<Category>,

    #[serde(rename = "sectioncat", default, skip_serializing_if = "Vec::is_empty")]
    pub section_cat: Vec<Category>,

    #[serde(rename = "pagecat", default, skip_serializing_if = "Vec::is_empty")]
    pub page_cat: Vec<Category>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub ver: Option<String>,

    // TODO: add properly
    // #[serde(rename = "privacypolicy", default, skip_serializing_if = "Vec::is_empty")]
    // privacy_policy: Option<String>,

    // TODO: add properly
    // paid:
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publisher: Option<Publisher>,

    // TODO: add properly
    // #[skip_serializing_if = "Option::is_none"]
    // content: Option<Content>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub keywords: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub ext: Option<serde_utils::Ext>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json;

    #[test]
    fn serialization_skip_fields() {
        let serialized = r#"{
            "id": "1234"
        }"#;

        let res = serde_json::from_str(serialized);

        let _: App = match res {
            Ok(x) => x,
            Err(e) => panic!("{:?}", e),
        };
    }
}