openrtb/v2_5/
app.rs

1// Copyright (c) 2018 The openrtb-rust authors
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use super::category::Category;
10use super::publisher::Publisher;
11use serde_utils;
12
13#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
14pub struct App {
15    pub id: String,
16
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub name: Option<String>,
19
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub bundle: Option<String>,
22
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub domain: Option<String>,
25
26    #[serde(rename = "storeurl", skip_serializing_if = "Option::is_none")]
27    pub store_url: Option<String>,
28
29    #[serde(default, skip_serializing_if = "Vec::is_empty")]
30    pub cat: Vec<Category>,
31
32    #[serde(rename = "sectioncat", default, skip_serializing_if = "Vec::is_empty")]
33    pub section_cat: Vec<Category>,
34
35    #[serde(rename = "pagecat", default, skip_serializing_if = "Vec::is_empty")]
36    pub page_cat: Vec<Category>,
37
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub ver: Option<String>,
40
41    // TODO: add properly
42    // #[serde(rename = "privacypolicy", default, skip_serializing_if = "Vec::is_empty")]
43    // privacy_policy: Option<String>,
44
45    // TODO: add properly
46    // paid:
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub publisher: Option<Publisher>,
49
50    // TODO: add properly
51    // #[skip_serializing_if = "Option::is_none"]
52    // content: Option<Content>,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    pub keywords: Option<String>,
55
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub ext: Option<serde_utils::Ext>,
58}
59
60#[cfg(test)]
61mod tests {
62    use super::*;
63    use serde_json;
64
65    #[test]
66    fn serialization_skip_fields() {
67        let serialized = r#"{
68            "id": "1234"
69        }"#;
70
71        let res = serde_json::from_str(serialized);
72
73        let _: App = match res {
74            Ok(x) => x,
75            Err(e) => panic!("{:?}", e),
76        };
77    }
78}