Skip to content

Commit

Permalink
fix: fill defaults for non-required field of type "record" (#336)
Browse files Browse the repository at this point in the history
* fix: fill defaults for non-required field of type "record"

* Ignore fields which differ across kong versions from tests

* Add version check for test failing due to schema changes across versions

* Pin version to 3.3.0 for test failing due to  schema changes

* Add schema to test itself
As acme plugin's schema has varied a lot over different versions of kong, it is easier to handle if this is added to the test itself

---------

Co-authored-by: Nishant H <[email protected]>
Co-authored-by: Travis Raines <[email protected]>
  • Loading branch information
3 people authored Jun 6, 2023
1 parent 46c44eb commit 534c363
Show file tree
Hide file tree
Showing 2 changed files with 592 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kong/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ func fillConfigRecord(schema gjson.Result, config Configuration) Configuration {
}
}
ftype := value.Get(fname + ".type")
if ftype.String() == "record" {
frequired := value.Get(fname + ".required")
// Recursively fill defaults only if the field is either required or a subconfig is provided
if ftype.String() == "record" && (config[fname] != nil || (frequired.Exists() && frequired.Bool())) {
subConfig := config[fname]
if subConfig == nil {
subConfig = make(map[string]interface{})
Expand Down
Loading

0 comments on commit 534c363

Please sign in to comment.