mirror of
https://github.com/rancher/norman.git
synced 2025-05-11 01:25:54 +00:00
Random mapper fixes
This commit is contained in:
parent
b8622b9c90
commit
c61bcaf6c0
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rancher/norman/types/convert"
|
||||
"github.com/rancher/norman/types/definition"
|
||||
)
|
||||
|
||||
@ -92,9 +93,9 @@ func (t *typeMapper) ToInternal(data map[string]interface{}) {
|
||||
if schema.Mapper == nil {
|
||||
continue
|
||||
}
|
||||
datas, _ := data[fieldName].([]map[string]interface{})
|
||||
datas, _ := data[fieldName].([]interface{})
|
||||
for _, fieldData := range datas {
|
||||
schema.Mapper.ToInternal(fieldData)
|
||||
schema.Mapper.ToInternal(convert.ToMapInterface(fieldData))
|
||||
}
|
||||
}
|
||||
|
||||
|
27
types/mapper/changetype.go
Normal file
27
types/mapper/changetype.go
Normal file
@ -0,0 +1,27 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/types"
|
||||
)
|
||||
|
||||
type ChangeType struct {
|
||||
Field string
|
||||
Type string
|
||||
}
|
||||
|
||||
func (c ChangeType) FromInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (c ChangeType) ToInternal(data map[string]interface{}) {
|
||||
}
|
||||
|
||||
func (c ChangeType) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
if err := ValidateField(c.Field, schema); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f := schema.ResourceFields[c.Field]
|
||||
f.Type = c.Type
|
||||
schema.ResourceFields[c.Field] = f
|
||||
return nil
|
||||
}
|
@ -8,7 +8,8 @@ var displayNameMappers = types.Mappers{
|
||||
&Move{From: "name", To: "id"},
|
||||
&Move{From: "displayName", To: "name"},
|
||||
Access{Fields: map[string]string{
|
||||
"id": "",
|
||||
"id": "",
|
||||
"name": "cru",
|
||||
}},
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
func NewMetadataMapper() types.Mapper {
|
||||
return types.Mappers{
|
||||
ChangeType{Field: "name", Type: "dnsLabel"},
|
||||
Drop{"generateName"},
|
||||
//Move{From: "selfLink", To: "resourcePath"},
|
||||
Drop{"selfLink"},
|
||||
|
@ -31,7 +31,7 @@ func (s SliceToMap) FromInternal(data map[string]interface{}) {
|
||||
|
||||
func (s SliceToMap) ToInternal(data map[string]interface{}) {
|
||||
datas, _ := data[s.Field].(map[string]interface{})
|
||||
var result []map[string]interface{}
|
||||
var result []interface{}
|
||||
|
||||
for name, item := range datas {
|
||||
mapItem, _ := item.(map[string]interface{})
|
||||
@ -43,6 +43,8 @@ func (s SliceToMap) ToInternal(data map[string]interface{}) {
|
||||
|
||||
if len(result) > 0 {
|
||||
data[s.Field] = result
|
||||
} else if datas != nil {
|
||||
data[s.Field] = result
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,10 +117,10 @@ type Field struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Default interface{} `json:"default,omitempty"`
|
||||
Nullable bool `json:"nullable,omitempty"`
|
||||
Create bool `json:"create,omitempty"`
|
||||
Create bool `json:"create"`
|
||||
WriteOnly bool `json:"writeOnly,omitempty"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
Update bool `json:"update,omitempty"`
|
||||
Update bool `json:"update"`
|
||||
MinLength *int64 `json:"minLength,omitempty"`
|
||||
MaxLength *int64 `json:"maxLength,omitempty"`
|
||||
Min *int64 `json:"min,omitempty"`
|
||||
|
@ -84,6 +84,10 @@ func GetValue(data map[string]interface{}, keys ...string) (interface{}, bool) {
|
||||
}
|
||||
|
||||
func PutValue(data map[string]interface{}, val interface{}, keys ...string) {
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// This is so ugly
|
||||
for i, key := range keys {
|
||||
if i == len(keys)-1 {
|
||||
|
Loading…
Reference in New Issue
Block a user