github.com/rancher/types@v0.0.0-20220328215343-4370ff10ecd5/mapper/creator.go (about)

     1  package mapper
     2  
     3  import (
     4  	"github.com/rancher/norman/types"
     5  	"github.com/rancher/norman/types/mapper"
     6  )
     7  
     8  type Creator struct {
     9  	m types.Mapper
    10  }
    11  
    12  func (c *Creator) FromInternal(data map[string]interface{}) {
    13  	if c.m != nil {
    14  		c.m.FromInternal(data)
    15  	}
    16  }
    17  
    18  func (c *Creator) ToInternal(data map[string]interface{}) error {
    19  	if c.m != nil {
    20  		return c.m.ToInternal(data)
    21  	}
    22  	return nil
    23  }
    24  
    25  func (c *Creator) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
    26  	if schema.CanList(nil) == nil && schema.CanCreate(nil) == nil {
    27  		schema.ResourceFields["creatorId"] = types.Field{
    28  			Type:     "reference[/v3/schemas/user]",
    29  			CodeName: "CreatorID",
    30  		}
    31  		c.m = &mapper.AnnotationField{Field: "creatorId"}
    32  		return c.m.ModifySchema(schema, schemas)
    33  	}
    34  	return nil
    35  }