mirror of
https://github.com/rancher/types.git
synced 2025-06-24 04:37:03 +00:00
Add creator to schemas
This commit is contained in:
parent
ee9dc3fbfa
commit
84e83e6ac9
@ -3,6 +3,7 @@ package factory
|
||||
import (
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/rancher/norman/types/factory"
|
||||
m "github.com/rancher/norman/types/mapper"
|
||||
"github.com/rancher/types/mapper"
|
||||
)
|
||||
|
||||
@ -21,6 +22,9 @@ func Schemas(version *types.APIVersion) *types.Schemas {
|
||||
})
|
||||
return mappers
|
||||
}
|
||||
basePostFunc := schemas.DefaultPostMappers
|
||||
schemas.DefaultPostMappers = func() []types.Mapper {
|
||||
return append(basePostFunc(), &mapper.Creator{})
|
||||
}
|
||||
return schemas
|
||||
}
|
||||
|
33
mapper/creator.go
Normal file
33
mapper/creator.go
Normal file
@ -0,0 +1,33 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"github.com/rancher/norman/types"
|
||||
"github.com/rancher/norman/types/mapper"
|
||||
)
|
||||
|
||||
type Creator struct {
|
||||
m types.Mapper
|
||||
}
|
||||
|
||||
func (c *Creator) FromInternal(data map[string]interface{}) {
|
||||
if c.m != nil {
|
||||
c.m.FromInternal(data)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Creator) ToInternal(data map[string]interface{}) {
|
||||
if c.m != nil {
|
||||
c.m.ToInternal(data)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Creator) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
|
||||
if schema.CanList() && schema.CanCreate() {
|
||||
schema.ResourceFields["creatorId"] = types.Field{
|
||||
Type: "reference[user]",
|
||||
}
|
||||
c.m = &mapper.AnnotationField{Field: "creatorId"}
|
||||
return c.m.ModifySchema(schema, schemas)
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user