func checkMapKeys()

in pkg/api/strictjson.go [23:62]


func checkMapKeys(o map[string]interface{}, types ...reflect.Type) error {
	fieldMap := createJSONFieldMap(types)
	for k, v := range o {
		f, present := fieldMap[strings.ToLower(k)]
		if !present {
			return errors.Errorf("Unknown JSON tag %s", k)
		}
		if f.Type.Kind() == reflect.Struct && v != nil {
			if childMap, exists := v.(map[string]interface{}); exists {
				if e := checkMapKeys(childMap, f.Type); e != nil {
					return e
				}
			}
		}
		if f.Type.Kind() == reflect.Slice && v != nil {
			elementType := f.Type.Elem()
			if elementType.Kind() == reflect.Ptr {
				elementType = elementType.Elem()
			}
			if childSlice, exists := v.([]interface{}); exists {
				for _, child := range childSlice {
					if childMap, exists := child.(map[string]interface{}); exists {
						if e := checkMapKeys(childMap, elementType); e != nil {
							return e
						}
					}
				}
			}
		}
		if f.Type.Kind() == reflect.Ptr && v != nil {
			elementType := f.Type.Elem()
			if childMap, exists := v.(map[string]interface{}); exists {
				if e := checkMapKeys(childMap, elementType); e != nil {
					return e
				}
			}
		}
	}
	return nil
}