bsm / openrtb

OpenRTB protocol defintions for Go
Other
287 stars 119 forks source link

Validatiors not conforming to IAB specifications ? #78

Open renomarx opened 3 years ago

renomarx commented 3 years ago

Hello,

I think there are some contradictions with IAB OpenRTB specifications on validators:

For example, in IAB specifications, it seems that an imp object can contain a video object and/or a banner object.

The presence of a Videoas a subordinate ofthe Impobject indicates that this impression is offered as a video type impression. At the publisher’s discretion, that same impression may also be offered as banner, audio, and/or native by also including as Impsubordinates objects of those types. However, any given bid for the impression must conform to one of the offered types.

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

But here is the code of the validator:


func (imp *Impression) assetCount() int {
    n := 0
    if imp.Banner != nil {
        n++
    }
    if imp.Video != nil {
        n++
    }
    if imp.Native != nil {
        n++
    }
    return n
}

// Validate the `imp` object
func (imp *Impression) Validate() error {
    if imp.ID == "" {
        return ErrInvalidImpNoID
    }

    if count := imp.assetCount(); count > 1 {
        return ErrInvalidImpMultiAssets
    }

    if imp.Video != nil {
        if err := imp.Video.Validate(); err != nil {
            return err
        }
    }

    return nil
}

Is there any particular reason for that behavior ?

dim commented 3 years ago

Good point, do you mind adding a pull request to address?

renomarx commented 3 years ago

Sure, I'll do that by the end of next week.