openrtb_native1/response/image.rs
1/// 5.4 Image Response Object
2///
3/// Corresponds to the Image Object in the request. The Image object to be used for all image
4/// elements of the Native ad such as Icons, Main Image, etc.
5/// It is recommended that if assetsurl/dcourl is being used rather than embedded assets, that an
6/// image of each recommended aspect ratio (per the Image Types table) be provided for image type 3.
7#[derive(serde::Serialize, serde::Deserialize, Default, Debug, PartialEq, Clone)]
8pub struct Image {
9 /// optional; integer; -
10 /// Required for assetsurl or dcourl responses, not required for embedded asset responses. The
11 /// type of image element being submitted from the Image Asset Types table.
12 #[serde(default, skip_serializing_if = "Option::is_none")]
13 pub r#type: Option<crate::ImageAssetType>,
14
15 /// required; string; -
16 /// The text associated with the text element.
17 pub url: String,
18
19 /// recommended; integer; -
20 /// Width of the image in pixels. Recommended for embedded asset responses. Required for
21 /// assetsurl/dcourlresponses if multiple assets of same type submitted.
22 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub w: Option<i32>,
24
25 /// recommended; integer; -
26 /// Height of the image in pixels. Recommended for embedded asset responses. Required for
27 /// assetsurl/dcourl responses if multiple assets of same type submitted.
28 #[serde(default, skip_serializing_if = "Option::is_none")]
29 pub h: Option<i32>,
30
31 /// optional; object; -
32 /// This object is a placeholder that may contain custom JSON agreed to by the parties to
33 /// support flexibility beyond the standard defined in this specification.
34 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub ext: Option<serde_json::Map<String, serde_json::Value>>,
36}
37
38#[cfg(test)]
39mod test {
40 use super::*;
41
42 #[test]
43 fn json() -> serde_json::Result<()> {
44 let json = r#"{"url":""}"#;
45 let o1 = Image::default();
46 assert_eq!(serde_json::to_string(&o1)?, json);
47 assert_eq!(o1, serde_json::from_str::<Image>(json)?);
48
49 Ok(())
50 }
51}