openrtb2/
bid_response.rs

1/// 4.2.1 Object: BidResponse
2///
3/// This object is the top-level bid response object (i.e., the unnamed outer JSON object). The id
4/// attribute is a reflection of the bid request ID for logging purposes. Similarly, bidid is an
5/// optional response tracking ID for bidders. If specified, it can be included in the subsequent
6/// win notice call if the bidder wins. At least one seatbid object is required, which contains at
7/// least one bid for an impression. Other attributes are optional.
8///
9/// To express a “no-bid”, the options are to return an empty response with HTTP 204. Alternately if
10/// the bidder wishes to convey to the exchange a reason for not bidding, just a BidResponse object
11/// is returned with a reason code in the nbr attribute.
12#[derive(serde::Serialize, serde::Deserialize, Default, Debug, PartialEq, Clone)]
13pub struct BidResponse {
14    /// string; required
15    /// ID of the bid request to which this is a response.
16    pub id: String,
17
18    /// object array
19    /// Array of seatbid objects; 1+ required if a bid is to be made.
20    #[serde(default, skip_serializing_if = "Option::is_none")]
21    pub seatbid: Option<Vec<crate::SeatBid>>,
22
23    /// string
24    /// Bidder generated response ID to assist with logging/tracking.
25    #[serde(default, skip_serializing_if = "Option::is_none")]
26    pub bidid: Option<String>,
27
28    /// string; default “USD”
29    /// Bid currency using ISO-4217 alpha codes.
30    // TODO: ISO-4217 alpha
31    #[serde(default, skip_serializing_if = "default_ext::DefaultExt::is_default")]
32    pub cur: String,
33
34    /// string
35    /// Optional feature to allow a bidder to set data in the exchange’s cookie. The string must be
36    /// in base85 cookie safe characters and be in any format. Proper JSON encoding must be used to
37    /// include “escaped” quotation marks.
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub customdata: Option<String>,
40
41    /// integer
42    /// Reason for not bidding. Refer to List 5.24.
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub nbr: Option<crate::NoBidReason>,
45
46    /// object
47    /// Placeholder for bidder-specific extensions to OpenRTB.
48    #[serde(default, skip_serializing_if = "Option::is_none")]
49    pub ext: Option<serde_json::Map<String, serde_json::Value>>,
50}
51
52#[cfg(test)]
53mod test {
54    use super::*;
55
56    #[test]
57    fn json() -> serde_json::Result<()> {
58        assert!(serde_json::from_str::<BidResponse>("{}").is_err());
59
60        let json = r#"{"id":""}"#;
61        let o1 = BidResponse::default();
62        assert_eq!(serde_json::to_string(&o1)?, json);
63        assert_eq!(o1, serde_json::from_str::<BidResponse>(json)?);
64
65        Ok(())
66    }
67}