openrtb_native1/request/
request.rs

1/// 4.1 Native Markup Request Object
2///
3/// The Native Object defines the native advertising opportunity available for bid via this bid
4/// request. It will be included as a JSON-encoded string in the bid request’s imp.native field or
5/// as a direct JSON object, depending on the choice of the exchange. While OpenRTB 2.x officially
6/// supports only JSON-encoded strings, many exchanges have implemented a formal object. Check with
7/// your integration docs.
8#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Clone)]
9pub struct Request {
10    /// optional; string; 1.2
11    /// Version of the Native Markup version in use.
12    #[serde(default)]
13    pub ver: crate::Version,
14
15    /// recommended; integer; -
16    /// The context in which the ad appears. See Table of Context IDs below for a list of supported
17    /// context types.
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub context: Option<crate::ContextType>,
20
21    /// optional; integer; -
22    /// A more detailed context in which the ad appears. See Table of Context SubType IDs below for
23    /// a list of supported context subtypes.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub contextsubtype: Option<crate::ContextSubType>,
26
27    /// recommended; integer; -
28    /// The design/format/layout of the ad unit being offered. See Table of Placement Type IDs
29    /// below for a list of supported placement types.
30    #[serde(default, skip_serializing_if = "Option::is_none")]
31    pub plcmttype: Option<crate::PlacementType>,
32
33    /// optional; integer; 1
34    /// The number of identical placements in this Layout. Refer Section 8.1 Multiplacement Bid
35    /// Requests for further detail.
36    #[serde(
37        default = "default_plcmtcnt",
38        skip_serializing_if = "is_default_plcmtcnt"
39    )]
40    pub plcmtcnt: i32,
41
42    /// 0 for the first ad, 1 for the second ad, and so on. Note this would generally NOT be used
43    /// in combination with plcmtcnt - either you are auctioning multiple identical placements (in
44    /// which case plcmtcnt>1, seq=0) or you are holding separate auctions for distinct items in
45    /// the feed (in which case plcmtcnt=1, seq=>=1)
46    #[serde(default, skip_serializing_if = "default_ext::DefaultExt::is_default")]
47    pub seq: i32,
48
49    /// required; array of objects; -
50    /// An array of Asset Objects. Any bid response must comply with the array of elements
51    /// expressed in the bid request.
52    pub assets: Vec<crate::request::Asset>,
53
54    /// optional; integer; 0
55    /// Whether the supply source / impression supports returning an assetsurl instead of an asset
56    /// object. 0 or the absence of the field indicates no such support.
57    #[serde(
58        default,
59        skip_serializing_if = "default_ext::DefaultExt::is_default",
60        with = "crate::serde::i32_as_bool"
61    )]
62    pub aurlsupport: bool,
63
64    /// optional; integer; 0
65    /// Whether the supply source / impression supports returning a dco url instead of an asset
66    /// object. 0 or the absence of the field indicates no such support. Beta feature.
67    #[serde(
68        default,
69        skip_serializing_if = "default_ext::DefaultExt::is_default",
70        with = "crate::serde::i32_as_bool"
71    )]
72    pub durlsupport: bool,
73
74    /// optional; array of objects; -
75    /// Specifies what type of event tracking is supported - see Event Trackers Request Object.
76    #[serde(default, skip_serializing_if = "Option::is_none")]
77    pub eventtrackers: Option<Vec<crate::request::EventTracker>>,
78
79    /// recommended; integer; 0
80    /// Set to 1 when the native ad supports buyer-specific privacy notice. Set to 0 (or field
81    /// absent) when the native ad doesn’t support custom privacy links or if support is unknown.
82    #[serde(
83        default,
84        skip_serializing_if = "default_ext::DefaultExt::is_default",
85        with = "crate::serde::i32_as_bool"
86    )]
87    pub privacy: bool,
88
89    /// optional; object; -
90    /// This object is a placeholder that may contain custom JSON agreed to by the parties to
91    /// support flexibility beyond the standard defined in this specification.
92    #[serde(default, skip_serializing_if = "Option::is_none")]
93    pub ext: Option<serde_json::Map<String, serde_json::Value>>,
94}
95
96impl Default for Request {
97    fn default() -> Self {
98        Self {
99            ver: Default::default(),
100            context: Default::default(),
101            contextsubtype: Default::default(),
102            plcmttype: Default::default(),
103            plcmtcnt: default_plcmtcnt(),
104            seq: Default::default(),
105            assets: Default::default(),
106            aurlsupport: Default::default(),
107            durlsupport: Default::default(),
108            eventtrackers: Default::default(),
109            privacy: Default::default(),
110            ext: Default::default(),
111        }
112    }
113}
114
115fn default_plcmtcnt() -> i32 {
116    1
117}
118
119fn is_default_plcmtcnt(v: &i32) -> bool {
120    *v == default_plcmtcnt()
121}
122
123#[cfg(test)]
124mod test {
125    use super::*;
126
127    #[test]
128    fn json() -> serde_json::Result<()> {
129        let json = r#"{"ver":"1.2","assets":[]}"#;
130        let o1 = Request::default();
131        assert_eq!(serde_json::to_string(&o1)?, json);
132        assert_eq!(o1, serde_json::from_str::<Request>(json)?);
133
134        Ok(())
135    }
136}