Skip to content

Commit

Permalink
Adtelligent: ext aid type (#3676)
Browse files Browse the repository at this point in the history
authored by @dkornet-ad
  • Loading branch information
dkornet-ad authored Aug 6, 2024
1 parent c50e264 commit c3d8379
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 22 deletions.
8 changes: 7 additions & 1 deletion adapters/adtarget/adtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ func validateImpressionAndSetExt(imp *openrtb2.Imp) (int, error) {

imp.Ext = impExtBuffer

return impExt.SourceId, nil
aid, err := impExt.SourceId.Int64()
if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, aid parsing err: %s", imp.ID, err),
}
}
return int(aid), nil
}

// Builder builds a new instance of the Adtarget adapter for the given bidder with the given config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"expectedMakeRequestsErrors": [
{
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: cannot unmarshal string into Go struct field ExtImpAdtarget.aid of type int",
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: invalid number literal, trying to unmarshal \"\\\"some string instead of int\\\"\" into Number",
"comparison": "literal"
}
]
Expand Down
12 changes: 8 additions & 4 deletions adapters/adtarget/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ func TestInvalidParams(t *testing.T) {

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderAdtarget, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
ext := openrtb_ext.ExtImpAdtarget{}
err = json.Unmarshal([]byte(invalidParam), &ext)
if err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}
}

var validParams = []string{
`{"aid":123}`,
`{"aid":"123"}`,
`{"aid":123,"placementId":1234}`,
`{"aid":123,"siteId":4321}`,
`{"aid":123,"siteId":0,"bidFloor":0}`,
`{"aid":"123","siteId":0,"bidFloor":0}`,
}

var invalidParams = []string{
Expand All @@ -53,8 +58,7 @@ var invalidParams = []string{
`4.2`,
`[]`,
`{}`,
`{"aid":"123"}`,
`{"aid":"0"}`,
`{"aid":"qwerty"}`,
`{"aid":"123","placementId":"123"}`,
`{"aid":123, "placementId":"123", "siteId":"321"}`,
}
8 changes: 7 additions & 1 deletion adapters/adtelligent/adtelligent.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ func validateImpression(imp *openrtb2.Imp) (int, error) {

imp.Ext = impExtBuffer

return impExt.SourceId, nil
aid, err := impExt.SourceId.Int64()
if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, aid parsing err: %s", imp.ID, err),
}
}
return int(aid), nil
}

// Builder builds a new instance of the Adtelligent adapter for the given bidder with the given config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"expectedMakeRequestsErrors": [
{
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: cannot unmarshal string into Go struct field ExtImpAdtelligent.aid of type int",
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: invalid number literal, trying to unmarshal \"\\\"some string instead of int\\\"\" into Number",
"comparison": "literal"
}
]
Expand Down
12 changes: 8 additions & 4 deletions adapters/adtelligent/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ func TestInvalidParams(t *testing.T) {

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderAdtelligent, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
ext := openrtb_ext.ExtImpAdtelligent{}
err = json.Unmarshal([]byte(invalidParam), &ext)
if err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}
}

var validParams = []string{
`{"aid":123}`,
`{"aid":"123"}`,
`{"aid":123,"placementId":1234}`,
`{"aid":123,"siteId":4321}`,
`{"aid":123,"siteId":0,"bidFloor":0}`,
`{"aid":"123","siteId":0,"bidFloor":0}`,
}

var invalidParams = []string{
Expand All @@ -53,8 +58,7 @@ var invalidParams = []string{
`4.2`,
`[]`,
`{}`,
`{"aid":"123"}`,
`{"aid":"0"}`,
`{"aid":"qwerty"}`,
`{"aid":"123","placementId":"123"}`,
`{"aid":123, "placementId":"123", "siteId":"321"}`,
}
10 changes: 6 additions & 4 deletions openrtb_ext/imp_adtarget.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package openrtb_ext

import "encoding/json"

// ExtImpAdtarget defines the contract for bidrequest.imp[i].ext.prebid.bidder.adtarget
type ExtImpAdtarget struct {
SourceId int `json:"aid"`
PlacementId int `json:"placementId,omitempty"`
SiteId int `json:"siteId,omitempty"`
BidFloor float64 `json:"bidFloor,omitempty"`
SourceId json.Number `json:"aid"`
PlacementId int `json:"placementId,omitempty"`
SiteId int `json:"siteId,omitempty"`
BidFloor float64 `json:"bidFloor,omitempty"`
}
10 changes: 6 additions & 4 deletions openrtb_ext/imp_adtelligent.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package openrtb_ext

import "encoding/json"

// ExtImpAdtelligent defines the contract for bidrequest.imp[i].ext.prebid.bidder.adtelligent
type ExtImpAdtelligent struct {
SourceId int `json:"aid"`
PlacementId int `json:"placementId,omitempty"`
SiteId int `json:"siteId,omitempty"`
BidFloor float64 `json:"bidFloor,omitempty"`
SourceId json.Number `json:"aid"`
PlacementId int `json:"placementId,omitempty"`
SiteId int `json:"siteId,omitempty"`
BidFloor float64 `json:"bidFloor,omitempty"`
}
5 changes: 4 additions & 1 deletion static/bidder-params/adtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"description": "An ID which identifies the site selling the impression"
},
"aid": {
"type": "integer",
"type": [
"integer",
"string"
],
"description": "An ID which identifies the channel"
},
"bidFloor": {
Expand Down
5 changes: 4 additions & 1 deletion static/bidder-params/adtelligent.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"description": "An ID which identifies the site selling the impression"
},
"aid": {
"type": "integer",
"type": [
"integer",
"string"
],
"description": "An ID which identifies the channel"
},
"bidFloor": {
Expand Down

0 comments on commit c3d8379

Please sign in to comment.