From f14e113e82ee185efcb4f915127528f104775d80 Mon Sep 17 00:00:00 2001 From: Scott Kay Date: Fri, 13 Dec 2024 18:08:55 -0500 Subject: [PATCH] OpenRTB 2.6-202402 + OpenRTB 2.6-202409 Field Support (#4100) --- go.mod | 2 +- go.sum | 2 + openrtb_ext/convert_down.go | 40 +++++++++++--- openrtb_ext/convert_down_test.go | 92 ++++++++++++++++++++++++++++++-- 4 files changed, 123 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index db378338fe..55ac94b617 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/prebid/go-gdpr v1.12.0 github.com/prebid/go-gpp v0.2.0 - github.com/prebid/openrtb/v20 v20.1.0 + github.com/prebid/openrtb/v20 v20.3.0 github.com/prometheus/client_golang v1.12.1 github.com/prometheus/client_model v0.2.0 github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 diff --git a/go.sum b/go.sum index bf94ffbc7f..d176e89dda 100644 --- a/go.sum +++ b/go.sum @@ -410,6 +410,8 @@ github.com/prebid/go-gpp v0.2.0 h1:41Ssxd4Zxr50WgwG1q/1+6awGU3pFnwV7FR4XCLQSuM= github.com/prebid/go-gpp v0.2.0/go.mod h1:b0TLoVln+HXFD9L9xeimxIH3FN8WDKPJ42auslxEkow= github.com/prebid/openrtb/v20 v20.1.0 h1:Rb+Z3H3UxiqqnjgJK3R9Wt73ibrh7HPzG7ikBckQNqc= github.com/prebid/openrtb/v20 v20.1.0/go.mod h1:hLBrA/APkSrxs5MaW639l+y/EAHivDfRagO2TX/wbSc= +github.com/prebid/openrtb/v20 v20.3.0 h1:56z5mIrZ4FdjKxiu3Del0O4890f4AZpvz5PgPLMY1j0= +github.com/prebid/openrtb/v20 v20.3.0/go.mod h1:hLBrA/APkSrxs5MaW639l+y/EAHivDfRagO2TX/wbSc= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= diff --git a/openrtb_ext/convert_down.go b/openrtb_ext/convert_down.go index bfb6028d8c..2bd8a1ba5b 100644 --- a/openrtb_ext/convert_down.go +++ b/openrtb_ext/convert_down.go @@ -1,5 +1,7 @@ package openrtb_ext +import "github.com/prebid/openrtb/v20/adcom1" + func ConvertDownTo25(r *RequestWrapper) error { // schain if err := moveSupplyChainFrom26To25(r); err != nil { @@ -174,9 +176,9 @@ func moveRewardedFrom26ToPrebidExt(i *ImpWrapper) error { return nil } -// clear26Fields sets all fields introduced in OpenRTB 2.6 to default values, which +// Clear26Fields sets all fields introduced in OpenRTB 2.6 to default values, which // will cause them to be omitted during json marshal. -func clear26Fields(r *RequestWrapper) { +func Clear26Fields(r *RequestWrapper) { r.WLangB = nil r.CatTax = 0 @@ -267,9 +269,9 @@ func clear26Fields(r *RequestWrapper) { } } -// clear202211Fields sets all fields introduced in OpenRTB 2.6-202211 to default values +// Clear202211Fields sets all fields introduced in OpenRTB 2.6-202211 to default values // which will cause them to be omitted during json marshal. -func clear202211Fields(r *RequestWrapper) { +func Clear202211Fields(r *RequestWrapper) { r.DOOH = nil if app := r.App; app != nil { @@ -291,9 +293,9 @@ func clear202211Fields(r *RequestWrapper) { } } -// clear202303Fields sets all fields introduced in OpenRTB 2.6-202303 to default values +// Clear202303Fields sets all fields introduced in OpenRTB 2.6-202303 to default values // which will cause them to be omitted during json marshal. -func clear202303Fields(r *RequestWrapper) { +func Clear202303Fields(r *RequestWrapper) { for _, imp := range r.GetImp() { imp.Refresh = nil @@ -303,9 +305,9 @@ func clear202303Fields(r *RequestWrapper) { } } -// clear202309Fields sets all fields introduced in OpenRTB 2.6-202309 to default values +// Clear202309Fields sets all fields introduced in OpenRTB 2.6-202309 to default values // which will cause them to be omitted during json marshal. -func clear202309Fields(r *RequestWrapper) { +func Clear202309Fields(r *RequestWrapper) { r.ACat = nil for _, imp := range r.GetImp() { @@ -326,3 +328,25 @@ func clear202309Fields(r *RequestWrapper) { } } } + +// Clear202402Fields sets all fields introduced in OpenRTB 2.6-202402 to default values +// which will cause them to be omitted during json marshal. +func Clear202402Fields(r *RequestWrapper) { + for _, imp := range r.GetImp() { + if video := imp.Video; video != nil { + video.PodDedupe = nil + } + } +} + +// Clear202409Fields sets all fields introduced in OpenRTB 2.6-202409 to default values +// which will cause them to be omitted during json marshal. +func Clear202409Fields(r *RequestWrapper) { + if user := r.User; user != nil { + for i := range user.EIDs { + user.EIDs[i].Inserter = "" + user.EIDs[i].Matcher = "" + user.EIDs[i].MM = adcom1.MatchMethodUnknown + } + } +} diff --git a/openrtb_ext/convert_down_test.go b/openrtb_ext/convert_down_test.go index f32f3da04b..684ae5cda4 100644 --- a/openrtb_ext/convert_down_test.go +++ b/openrtb_ext/convert_down_test.go @@ -578,7 +578,7 @@ func TestClear26Fields(t *testing.T) { } r := &RequestWrapper{BidRequest: given} - clear26Fields(r) + Clear26Fields(r) assert.Equal(t, expected, r.BidRequest) } @@ -637,7 +637,7 @@ func TestClear202211Fields(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { r := &RequestWrapper{BidRequest: &test.given} - clear202211Fields(r) + Clear202211Fields(r) assert.Equal(t, &test.expected, r.BidRequest) }) } @@ -666,7 +666,7 @@ func TestClear202303Fields(t *testing.T) { } r := &RequestWrapper{BidRequest: &given} - clear202303Fields(r) + Clear202303Fields(r) assert.Equal(t, expected, given) } @@ -713,6 +713,90 @@ func TestClear202309Fields(t *testing.T) { } r := &RequestWrapper{BidRequest: &given} - clear202309Fields(r) + Clear202309Fields(r) assert.Equal(t, expected, given) } + +func TestClear202402Fields(t *testing.T) { + given := openrtb2.BidRequest{ + ID: "anyID", + Imp: []openrtb2.Imp{ + { + ID: "imp2", + Video: &openrtb2.Video{ + PodID: "1", + PodDedupe: []adcom1.PodDedupe{adcom1.PodDedupeADomain}, + }, + }, + }, + } + + expected := openrtb2.BidRequest{ + ID: "anyID", + Imp: []openrtb2.Imp{ + { + ID: "imp2", + Video: &openrtb2.Video{ + PodID: "1", + }, + }, + }, + } + + r := &RequestWrapper{BidRequest: &given} + Clear202402Fields(r) + assert.Equal(t, expected, given) +} + +func TestClear202409Fields(t *testing.T) { + testCases := []struct { + name string + given openrtb2.BidRequest + expected openrtb2.BidRequest + }{ + { + name: "user-nil", + given: openrtb2.BidRequest{User: nil}, + expected: openrtb2.BidRequest{User: nil}, + }, + { + name: "eids-nil", + given: openrtb2.BidRequest{User: &openrtb2.User{EIDs: nil}}, + expected: openrtb2.BidRequest{User: &openrtb2.User{EIDs: nil}}, + }, + { + name: "cleared", + given: openrtb2.BidRequest{ + User: &openrtb2.User{ + EIDs: []openrtb2.EID{ + { + Source: "anySource", + Inserter: "anyInserter", + Matcher: "anyMatcher", + MM: adcom1.MatchMethodBrowserCookieSync, + UIDs: []openrtb2.UID{{ID: "anyID"}}, + }, + }, + }, + }, + expected: openrtb2.BidRequest{ + User: &openrtb2.User{ + EIDs: []openrtb2.EID{ + { + Source: "anySource", + UIDs: []openrtb2.UID{{ID: "anyID"}}, + }, + }, + }, + }, + }, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + r := &RequestWrapper{BidRequest: &test.given} + Clear202409Fields(r) + assert.Equal(t, test.expected, test.given) + }) + } +}