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