Skip to content

Commit

Permalink
OpenRTB 2.6-202402 + OpenRTB 2.6-202409 Field Support (prebid#4100)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxNode authored and scr-oath committed Dec 16, 2024
1 parent 70018be commit 443d772
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
40 changes: 32 additions & 8 deletions openrtb_ext/convert_down.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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() {
Expand All @@ -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
}
}
}
92 changes: 88 additions & 4 deletions openrtb_ext/convert_down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func TestClear26Fields(t *testing.T) {
}

r := &RequestWrapper{BidRequest: given}
clear26Fields(r)
Clear26Fields(r)
assert.Equal(t, expected, r.BidRequest)
}

Expand Down Expand Up @@ -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)
})
}
Expand Down Expand Up @@ -666,7 +666,7 @@ func TestClear202303Fields(t *testing.T) {
}

r := &RequestWrapper{BidRequest: &given}
clear202303Fields(r)
Clear202303Fields(r)
assert.Equal(t, expected, given)
}

Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 443d772

Please sign in to comment.