Merge pull request #18 from elvinchan/17
#17 Add support for `map[string]interface{}` like type in schema
This commit is contained in:
commit
27beb50b64
@ -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 {
|
||||
|
@ -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...)
|
||||
|
Loading…
Reference in New Issue
Block a user