k-bx / openrtb-rust

OpenRTB v2.5 and OpenRTB Dynamic Native Ads v1.2 types for rust.
Apache License 2.0
16 stars 11 forks source link

Added additional flexibility to match spec #7

Closed justin-boshoven-vizio closed 1 year ago

justin-boshoven-vizio commented 1 year ago

Now capable of parsing all examples at https://github.com/openrtb/examples after they have been made valid json. I had to add commas and remove trailing commas to make them valid.

The spec: https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf

The big parts of this change were expanding flexibility of u8_to_bool and u8_to_mbool so that they can parse from true, false, 0, or 1.

The other odd one is adding anything_to_string that will take any valid json value and convert it to a String to support ids that may come in as integers from incorrect json.

See #3, this may help.

sriggin commented 1 year ago

This PR fixes the exact issues I was looking into recently, it'd be great to get this merged/released!

That said, here's a small change for the fork which addresses my above comment and issues encountered running cargo test:

diff --git a/src/v2_5/bid_request.rs b/src/v2_5/bid_request.rs
index 232f21e..a22c30d 100644
--- a/src/v2_5/bid_request.rs
+++ b/src/v2_5/bid_request.rs
@@ -177,7 +177,7 @@ impl BidRequest {
             user: None,
             test: false,
             auction_type: AuctionType::FirstPrice,
-            tmax: Some(0),
+            tmax: None,
             seat_whitelist: vec![],
             seat_blocklist: vec![],
             all_imps: false,
@@ -240,7 +240,7 @@ mod tests {
             user: None,
             test: false,
             auction_type: AuctionType::FirstPrice,
-            tmax: 0,
+            tmax: None,
             seat_whitelist: vec![],
             seat_blocklist: vec![],
             all_imps: false,
@@ -254,7 +254,7 @@ mod tests {
             ext: None,
         };

-        let expected = r#"{"id":"1234","imp":[],"at":1,"tmax":0}"#;
+        let expected = r#"{"id":"1234","imp":[],"at":1}"#;
         let serialized = serde_json::to_string(&b).unwrap();

         assert_eq!(expected, serialized)
@@ -285,7 +285,7 @@ mod tests {
             user: None,
             test: false,
             auction_type: AuctionType::SecondPricePlus,
-            tmax: 0,
+            tmax: None,
             seat_whitelist: vec![],
             seat_blocklist: vec![],
             all_imps: false,
justin-boshoven-vizio commented 1 year ago

What do we gotta do to get this thing checked in?

justin-boshoven-vizio commented 1 year ago

@sriggin You know how I can get this checked in?

k-bx commented 1 year ago

Hey @justin-boshoven-vizio , would you mind if I add you as a maintainer? Give me your crates username if yes

justin-boshoven-vizio commented 1 year ago

I think it matches my github username? justin-boshoven-vizio

k-bx commented 1 year ago

@justin-boshoven-vizio invitest sent!