Skip to content

Commit

Permalink
InitBidderParamsValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon committed Feb 27, 2024
1 parent 0fc3933 commit 9f13d75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion openrtb_ext/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,14 @@ func NewBidderParamsValidator(schemaDirectory string) (BidderParamValidator, err
schemaContents[alias] = parentSchemaContents
}

return InitBidderParamsValidator(schemaContents, schemas), nil
}

func InitBidderParamsValidator(schemaContents map[BidderName]string, schemas map[BidderName]*gojsonschema.Schema) *bidderParamValidator {
return &bidderParamValidator{
schemaContents: schemaContents,
parsedSchemas: schemas,
}, nil
}
}

func LoadSchema(schemaDirectory, filename string) (*gojsonschema.Schema, error) {
Expand Down
10 changes: 5 additions & 5 deletions router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func TestValidateDefaultAliases(t *testing.T) {
}

func TestBidderParamsCompactedOutput(t *testing.T) {
expectedFormattedResponse := `{"foo":{"$schema":"http://json-schema.org/draft-04/schema#","title":"Sample schema","description":"A sample schema to test the bidder/params endpoint","type":"object","properties":{"integer_param":{"type":"integer","minimum":1,"description":"The customer id provided by AAX."},"string_param_1":{"type":"string","minLength":1,"description":"Description blanks in between"},"string_param_2":{"type":"string","minLength":1,"description":"Description_with_no_blanks_in_between"}},"required":["integer_param","string_param_2"]}}`
expectedFormattedResponse := `{"foo":{"$schema":"http://json-schema.org/draft-04/schema#","title":"Sample schema","description":"A sample schema to test the bidder/params endpoint","type":"object","properties":{"integer_param":{"type":"integer","minimum":1,"description":"A customer id"},"string_param_1":{"type":"string","minLength":1,"description":"Text with blanks in between"},"string_param_2":{"type":"string","minLength":1,"description":"Text_with_no_blanks_in_between"}},"required":["integer_param","string_param_2"]}}`
inSchemaDirectory := "bidder_params_tests"
inSchemaFile := "foo.json"

Expand All @@ -300,10 +300,10 @@ func TestBidderParamsCompactedOutput(t *testing.T) {
fileBytes, err := os.ReadFile("bidder_params_tests/foo.json")
assert.NoError(t, err, "Error reading test schema file %s", inSchemaDirectory, inSchemaFile)

testParamsValidator := &bidderParamValidator{
parsedSchemas: map[BidderName]*gojsonschema.Schema{openrtb_ext.BidderName("foo"): fooSchema},
schemaContents: map[openrtb_ext.BidderName]string{openrtb_ext.BidderName("foo"): string(fileBytes)},
}
testParamsValidator := openrtb_ext.InitBidderParamsValidator(
map[openrtb_ext.BidderName]string{openrtb_ext.BidderName("foo"): string(fileBytes)},
map[openrtb_ext.BidderName]*gojsonschema.Schema{openrtb_ext.BidderName("foo"): fooSchema},
)

handler := newJsonDirectoryServer(inSchemaDirectory, testParamsValidator, nil, nil, biddermap)
recorder := httptest.NewRecorder()
Expand Down

0 comments on commit 9f13d75

Please sign in to comment.