Merge pull request #18 from elvinchan/17

#17 Add support for `map[string]interface{}` like type in schema
This commit is contained in:
陈文强 2019-01-08 08:50:36 +08:00 committed by GitHub
commit 27beb50b64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -141,9 +141,10 @@ func TestSchemaTypes(t *testing.T) {
var pe map[time.Time]string
var pf map[*int]string
type PU struct {
Unknown interface{}
Any interface{}
}
var pg PU
var ph map[string]interface{}
tests := []struct {
p interface{}
panic bool
@ -196,8 +197,13 @@ func TestSchemaTypes(t *testing.T) {
},
{
p: &pg,
panic: true,
name: "Struct inner invalid type",
panic: false,
name: "Struct interface field type",
},
{
p: &ph,
panic: false,
name: "Map interface value type",
},
}
for _, tt := range tests {

View File

@ -78,7 +78,7 @@ func isValidSchema(t reflect.Type, inner bool, pres ...reflect.Type) bool {
switch t.Kind() {
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr,
reflect.Float32, reflect.Float64, reflect.String:
reflect.Float32, reflect.Float64, reflect.String, reflect.Interface:
return true
case reflect.Array, reflect.Slice:
return isValidSchema(t.Elem(), inner, pres...)