Skip to content

Commit

Permalink
handle empty slices
Browse files Browse the repository at this point in the history
  • Loading branch information
karuppiah7890 committed Dec 29, 2019
1 parent 6dd5a81 commit 2e6de9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (p *property) readFromSliceDeep(v reflect.Value) {
p.Type = "string"
} else if jsType != "" {
p.Items = &property{}
if v.Len() == 0 {
p.Items.read(t.Elem(), "")
return
}
p.Items.readDeep(v.Index(0), "")
}
}
Expand Down
2 changes: 2 additions & 0 deletions jsonschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func TestLoadMapDeep(t *testing.T) {
"anotherBool": true,
"anotherInt": 1,
"anotherFloat": 1.699,
"emptySliceOfFloat": []float64{},
},
"aMapOfInterfaceToMapOfInterfaceToInterface": map[interface{}]interface{}{
"aPointerToMapOfInterfaceToInterface": &map[interface{}]interface{}{
Expand Down Expand Up @@ -386,6 +387,7 @@ func TestLoadMapDeep(t *testing.T) {
"anotherBool": {Type: "boolean"},
"anotherFloat": {Type: "number"},
"anotherInt": {Type: "integer"},
"emptySliceOfFloat": {Type: "array", Items: &property{Type: "number"}},
"justAnotherString": {Type: "string"},
},
},
Expand Down

0 comments on commit 2e6de9b

Please sign in to comment.