diff --git a/adapters/adtarget/adtarget.go b/adapters/adtarget/adtarget.go index 8c5d11704a5..7ec92c60a58 100644 --- a/adapters/adtarget/adtarget.go +++ b/adapters/adtarget/adtarget.go @@ -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. diff --git a/adapters/adtarget/adtargettest/supplemental/wrong-impression-ext.json b/adapters/adtarget/adtargettest/supplemental/wrong-impression-ext.json index 1986dfaf13f..ee59cf36439 100644 --- a/adapters/adtarget/adtargettest/supplemental/wrong-impression-ext.json +++ b/adapters/adtarget/adtargettest/supplemental/wrong-impression-ext.json @@ -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" } ] diff --git a/adapters/adtarget/params_test.go b/adapters/adtarget/params_test.go index d0993215086..9af435d5753 100644 --- a/adapters/adtarget/params_test.go +++ b/adapters/adtarget/params_test.go @@ -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{ @@ -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"}`, } diff --git a/adapters/adtelligent/adtelligent.go b/adapters/adtelligent/adtelligent.go index 492de0a364b..3bc27a2e604 100644 --- a/adapters/adtelligent/adtelligent.go +++ b/adapters/adtelligent/adtelligent.go @@ -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. diff --git a/adapters/adtelligent/adtelligenttest/supplemental/wrong-impression-ext.json b/adapters/adtelligent/adtelligenttest/supplemental/wrong-impression-ext.json index 63c587ed742..ee59cf36439 100644 --- a/adapters/adtelligent/adtelligenttest/supplemental/wrong-impression-ext.json +++ b/adapters/adtelligent/adtelligenttest/supplemental/wrong-impression-ext.json @@ -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" } ] diff --git a/adapters/adtelligent/params_test.go b/adapters/adtelligent/params_test.go index f86a7641af9..89fb7397795 100644 --- a/adapters/adtelligent/params_test.go +++ b/adapters/adtelligent/params_test.go @@ -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{ @@ -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"}`, } diff --git a/openrtb_ext/imp_adtarget.go b/openrtb_ext/imp_adtarget.go index ab6cb5642c6..aa3b6136e58 100644 --- a/openrtb_ext/imp_adtarget.go +++ b/openrtb_ext/imp_adtarget.go @@ -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"` } diff --git a/openrtb_ext/imp_adtelligent.go b/openrtb_ext/imp_adtelligent.go index c2233209352..b13c44ea360 100644 --- a/openrtb_ext/imp_adtelligent.go +++ b/openrtb_ext/imp_adtelligent.go @@ -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"` } diff --git a/static/bidder-params/adtarget.json b/static/bidder-params/adtarget.json index 195bf2dd430..980fb623786 100644 --- a/static/bidder-params/adtarget.json +++ b/static/bidder-params/adtarget.json @@ -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": { diff --git a/static/bidder-params/adtelligent.json b/static/bidder-params/adtelligent.json index db7931e1ec0..9b241bee149 100644 --- a/static/bidder-params/adtelligent.json +++ b/static/bidder-params/adtelligent.json @@ -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": {