Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.

Commit 3de9cb8

Browse files
authored
Updated price granularity unmarshal to accept empty values and ranges (prebid#1230)
1 parent 47e779b commit 3de9cb8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

openrtb_ext/request.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ func (pg *PriceGranularity) UnmarshalJSON(b []byte) error {
148148
}
149149
prevMax = gr.Max
150150
}
151-
} else {
152-
return errors.New("Price granularity error: empty granularity definition supplied")
151+
*pg = PriceGranularity(pgraw)
152+
return nil
153153
}
154-
*pg = PriceGranularity(pgraw)
154+
// Default to medium if no ranges are specified
155+
*pg = priceGranularityMed
155156
return nil
156157
}
157158

openrtb_ext/request_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,22 @@ var validGranularityTests []granularityTestData = []granularityTestData{
175175
},
176176
},
177177
},
178+
{
179+
json: []byte(`{}`),
180+
target: priceGranularityMed,
181+
},
182+
{
183+
json: []byte(`{"precision": 2}`),
184+
target: priceGranularityMed,
185+
},
186+
{
187+
json: []byte(`{"precision": 2, "ranges":[]}`),
188+
target: priceGranularityMed,
189+
},
178190
}
179191

180192
func TestGranularityUnmarshalBad(t *testing.T) {
181193
tests := [][]byte{
182-
[]byte(`{}`),
183194
[]byte(`[]`),
184195
[]byte(`{"precision": -1, "ranges": [{"max":20, "increment":0.5}]}`),
185196
[]byte(`{"ranges":[{"max":20, "increment": -1}]}`),

0 commit comments

Comments
 (0)