// createWorkItemTypePerson defines a work item type "person" that consists of // a required "name" field. func (s *workItemTypeSuite) createWorkItemTypePerson() (http.ResponseWriter, *app.WorkItemType) { // Create the type for the "color" field nameFieldDef := app.FieldDefinition{ Required: true, Type: &app.FieldType{ Kind: "string", }, } // Use the goa generated code to create a work item type payload := app.CreateWorkItemTypePayload{ Fields: map[string]*app.FieldDefinition{ "name": &nameFieldDef, }, Name: "person", } return test.CreateWorkitemtypeCreated(s.T(), nil, nil, s.typeCtrl, &payload) }
// createWorkItemTypeAnimal defines a work item type "animal" that consists of // two fields ("animal-type" and "color"). The type is mandatory but the color is not. func (s *workItemTypeSuite) createWorkItemTypeAnimal() (http.ResponseWriter, *app.WorkItemType) { // Create an enumeration of animal names typeStrings := []string{"elephant", "blue whale", "Tyrannosaurus rex"} // Convert string slice to slice of interface{} in O(n) time. typeEnum := make([]interface{}, len(typeStrings)) for i := range typeStrings { typeEnum[i] = typeStrings[i] } // Create the type for "animal-type" field based on the enum above stString := "string" typeFieldDef := app.FieldDefinition{ Required: true, Type: &app.FieldType{ BaseType: &stString, Kind: "enum", Values: typeEnum, }, } // Create the type for the "color" field colorFieldDef := app.FieldDefinition{ Required: false, Type: &app.FieldType{ Kind: "string", }, } // Use the goa generated code to create a work item type payload := app.CreateWorkItemTypePayload{ Fields: map[string]*app.FieldDefinition{ "animal_type": &typeFieldDef, "color": &colorFieldDef, }, Name: "animal", } return test.CreateWorkitemtypeCreated(s.T(), nil, nil, s.typeCtrl, &payload) }