Skip to content

Commit

Permalink
Fix conversion to JSON of empty YAML arrays (#683)
Browse files Browse the repository at this point in the history
We were not initializing arrays when converting from YAML to JSON, so
the ones that don't have elements were kept as null. This lead to
unexpected error messages about unexpected null values.
  • Loading branch information
jsoriano authored Dec 13, 2023
1 parent 8b05efd commit 71664a0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/go/internal/yamlschema/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func expandItemKey(c interface{}) interface{} {

// c is an array
if cArr, isArray := c.([]interface{}); isArray {
var arr []interface{}
arr := []interface{}{}
for _, ca := range cArr {
arr = append(arr, expandItemKey(ca))
}
Expand Down
1 change: 0 additions & 1 deletion code/go/pkg/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func TestValidateFile(t *testing.T) {
"data_stream/foo_stream/manifest.yml",
[]string{
"field streams.0.vars.1: options is required",
"field streams.0.vars.2.options: Invalid type. Expected: array, given: null",
"field streams.0.vars.3: Must not be present",
},
},
Expand Down
3 changes: 3 additions & 0 deletions spec/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
- description: Prepare for next version
type: enhancement
link: https://github.com/elastic/package-spec/pull/681
- description: Fix validation of empty arrays in YAML files
type: bugfix
link: https://github.com/elastic/package-spec/issues/683
- version: 3.0.3
changes:
- description: Do not require an object_type on objects with `enabled` set to `false`
Expand Down
3 changes: 3 additions & 0 deletions test/packages/good_v2/data_stream/foo/fields/some_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@
expected_values:
- artifact
- directory
- name: empty_expected_values
type: keyword
expected_values: []
3 changes: 3 additions & 0 deletions test/packages/good_v3/data_stream/foo/fields/some_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@
metrics:
- min
- max
- name: empty_expected_values
type: keyword
expected_values: []

0 comments on commit 71664a0

Please sign in to comment.