#17 Add support for map[string]interface{}
like type in schema
This commit is contained in:
parent
41e3ba6bb9
commit
9a98f95063
@ -141,9 +141,10 @@ func TestSchemaTypes(t *testing.T) {
|
|||||||
var pe map[time.Time]string
|
var pe map[time.Time]string
|
||||||
var pf map[*int]string
|
var pf map[*int]string
|
||||||
type PU struct {
|
type PU struct {
|
||||||
Unknown interface{}
|
Any interface{}
|
||||||
}
|
}
|
||||||
var pg PU
|
var pg PU
|
||||||
|
var ph map[string]interface{}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
p interface{}
|
p interface{}
|
||||||
panic bool
|
panic bool
|
||||||
@ -196,8 +197,13 @@ func TestSchemaTypes(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
p: &pg,
|
p: &pg,
|
||||||
panic: true,
|
panic: false,
|
||||||
name: "Struct inner invalid type",
|
name: "Struct interface field type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
p: &ph,
|
||||||
|
panic: false,
|
||||||
|
name: "Map interface value type",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -78,7 +78,7 @@ func isValidSchema(t reflect.Type, inner bool, pres ...reflect.Type) bool {
|
|||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
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.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
|
return true
|
||||||
case reflect.Array, reflect.Slice:
|
case reflect.Array, reflect.Slice:
|
||||||
return isValidSchema(t.Elem(), inner, pres...)
|
return isValidSchema(t.Elem(), inner, pres...)
|
||||||
|
Loading…
Reference in New Issue
Block a user