Skip to content

Commit

Permalink
fix handling of slice
Browse files Browse the repository at this point in the history
  • Loading branch information
karuppiah7890 committed Dec 29, 2019
1 parent d149f59 commit 6dd5a81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (p *property) readFromSliceDeep(v reflect.Value) {
p.Type = "string"
} else if jsType != "" {
p.Items = &property{}
p.Items.readDeep(v.Elem(), "")
p.Items.readDeep(v.Index(0), "")
}
}

Expand Down
4 changes: 4 additions & 0 deletions jsonschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func TestLoadMapDeep(t *testing.T) {
"aBool": true,
"anInt": 1,
"aFloat": 1.699,
"sliceOfString": []string{"something"},
"aMapOfStringToString": map[string]string{
"justAString": "ok3",
},
Expand All @@ -348,6 +349,7 @@ func TestLoadMapDeep(t *testing.T) {
"nilData": nil,
"zeroIntValue": 0,
"zeroStringValue": "",
"sliceOfInt": []int{1},
},
},
})
Expand All @@ -364,6 +366,7 @@ func TestLoadMapDeep(t *testing.T) {
"aBool": {Type: "boolean"},
"anInt": {Type: "integer"},
"aFloat": {Type: "number"},
"sliceOfString": {Type: "array", Items: &property{Type: "string"}},
"aMapOfStringToString": {
Type: "object",
Properties: map[string]*property{"justAString": {Type: "string"}},
Expand Down Expand Up @@ -397,6 +400,7 @@ func TestLoadMapDeep(t *testing.T) {
"anotherInt": {Type: "integer"},
"justAnotherString": {Type: "string"},
"nilData": {Type: "null"},
"sliceOfInt": {Type: "array", Items: &property{Type: "integer"}},
"zeroIntValue": {Type: "integer"},
"zeroStringValue": {Type: "string"},
},
Expand Down

0 comments on commit 6dd5a81

Please sign in to comment.