func ConvertWorkItem(request *goa.RequestData, wi workitem.WorkItem, additional ...WorkItemConvertFunc) *app.WorkItem {
	// construct default values from input WI
	selfURL := rest.AbsoluteURL(request, app.WorkitemHref(wi.SpaceID.String(), wi.ID))
	sourceLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type)+sourceLinkTypesRouteEnd)
	targetLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type)+targetLinkTypesRouteEnd)
	spaceSelfURL := rest.AbsoluteURL(request, app.SpaceHref(wi.SpaceID.String()))
	witSelfURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type))

	op := &app.WorkItem{
		ID:   &wi.ID,
		Type: APIStringTypeWorkItem,
		Attributes: map[string]interface{}{
			"version": wi.Version,
		},
		Relationships: &app.WorkItemRelationships{
			BaseType: &app.RelationBaseType{
				Data: &app.BaseTypeData{
					ID:   wi.Type,
					Type: APIStringTypeWorkItemType,
				},
				Links: &app.GenericLinks{
					Self: &witSelfURL,
				},
			},
			Space: app.NewSpaceRelation(wi.SpaceID, spaceSelfURL),
		},
		Links: &app.GenericLinksForWorkItem{
			Self:            &selfURL,
			SourceLinkTypes: &sourceLinkTypesURL,
			TargetLinkTypes: &targetLinkTypesURL,
		},
	}

	// Move fields into Relationships or Attributes as needed
	// TODO: Loop based on WorkItemType and match against Field.Type instead of directly to field value
	for name, val := range wi.Fields {
		switch name {
		case workitem.SystemAssignees:
			if val != nil {
				valArr := val.([]interface{})
				op.Relationships.Assignees = &app.RelationGenericList{
					Data: ConvertUsersSimple(request, valArr),
				}
			}
		case workitem.SystemCreator:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Creator = &app.RelationGeneric{
					Data: ConvertUserSimple(request, valStr),
				}
			}
		case workitem.SystemIteration:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Iteration = &app.RelationGeneric{
					Data: ConvertIterationSimple(request, valStr),
				}
			}
		case workitem.SystemArea:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Area = &app.RelationGeneric{
					Data: ConvertAreaSimple(request, valStr),
				}
			}

		case workitem.SystemTitle:
			// 'HTML escape' the title to prevent script injection
			op.Attributes[name] = html.EscapeString(val.(string))
		case workitem.SystemDescription:
			description := rendering.NewMarkupContentFromValue(val)
			if description != nil {
				op.Attributes[name] = (*description).Content
				op.Attributes[workitem.SystemDescriptionMarkup] = (*description).Markup
				// let's include the rendered description while 'HTML escaping' it to prevent script injection
				op.Attributes[workitem.SystemDescriptionRendered] =
					rendering.RenderMarkupToHTML(html.EscapeString((*description).Content), (*description).Markup)
			}
		case workitem.SystemCodebase:
			if val != nil {
				op.Attributes[name] = val
				// TODO: Following format is TBD and hence commented out
				// cb := val.(codebase.CodebaseContent)
				// urlparams := fmt.Sprintf("/codebase/generate?repo=%s&branch=%s&file=%s&line=%d", cb.Repository, cb.Branch, cb.FileName, cb.LineNumber)
				// doitURL := rest.AbsoluteURL(request, url.QueryEscape(urlparams))
				// op.Links.Doit = &doitURL
			}
		default:
			op.Attributes[name] = val
		}
	}
	if op.Relationships.Assignees == nil {
		op.Relationships.Assignees = &app.RelationGenericList{Data: nil}
	}
	if op.Relationships.Iteration == nil {
		op.Relationships.Iteration = &app.RelationGeneric{Data: nil}
	}
	if op.Relationships.Area == nil {
		op.Relationships.Area = &app.RelationGeneric{Data: nil}
	}
	// Always include Comments Link, but optionally use WorkItemIncludeCommentsAndTotal
	WorkItemIncludeComments(request, &wi, op)
	WorkItemIncludeChildren(request, &wi, op)
	for _, add := range additional {
		add(request, &wi, op)
	}
	return op
}
// ConvertWorkItem is responsible for converting given WorkItem model object into a
// response resource object by jsonapi.org specifications
ConvertWorkItem is responsible for converting given WorkItem model object into a
response resource object by jsonapi.org specifications
// ConvertWorkItem is responsible for converting given WorkItem model object into a // response resource object by jsonapi . org specifications
func ConvertWorkItem(request *goa.RequestData, wi workitem.WorkItem, additional ...WorkItemConvertFunc) *app.WorkItem {
	selfURL := rest.AbsoluteURL(request, app.WorkitemHref(wi.SpaceID.String(), wi.ID))
	sourceLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type)+sourceLinkTypesRouteEnd)
	targetLinkTypesURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type)+targetLinkTypesRouteEnd)
	spaceSelfURL := rest.AbsoluteURL(request, app.SpaceHref(wi.SpaceID.String()))
	witSelfURL := rest.AbsoluteURL(request, app.WorkitemtypeHref(wi.SpaceID.String(), wi.Type))
	op := &app.WorkItem{
		ID:   &wi.ID,
		Type: APIStringTypeWorkItem,
		Attributes: map[string]interface{}{
			"version": wi.Version,
		},
		Relationships: &app.WorkItemRelationships{
			BaseType: &app.RelationBaseType{
				Data: &app.BaseTypeData{
					ID:   wi.Type,
					Type: APIStringTypeWorkItemType,
				},
				Links: &app.GenericLinks{
					Self: &witSelfURL,
				},
			},
			Space: app.NewSpaceRelation(wi.SpaceID, spaceSelfURL),
		},
		Links: &app.GenericLinksForWorkItem{
			Self:            &selfURL,
			SourceLinkTypes: &sourceLinkTypesURL,
			TargetLinkTypes: &targetLinkTypesURL,
		},
	}
	for name, val := range wi.Fields {
		switch name {
		case workitem.SystemAssignees:
			if val != nil {
				valArr := val.([]interface{})
				op.Relationships.Assignees = &app.RelationGenericList{
					Data: ConvertUsersSimple(request, valArr),
				}
			}
		case workitem.SystemCreator:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Creator = &app.RelationGeneric{
					Data: ConvertUserSimple(request, valStr),
				}
			}
		case workitem.SystemIteration:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Iteration = &app.RelationGeneric{
					Data: ConvertIterationSimple(request, valStr),
				}
			}
		case workitem.SystemArea:
			if val != nil {
				valStr := val.(string)
				op.Relationships.Area = &app.RelationGeneric{
					Data: ConvertAreaSimple(request, valStr),
				}
			}
		case workitem.SystemTitle:
			op.Attributes[name] = html.EscapeString(val.(string))
		case workitem.SystemDescription:
			description := rendering.NewMarkupContentFromValue(val)
			if description != nil {
				op.Attributes[name] = (*description).Content
				op.Attributes[workitem.SystemDescriptionMarkup] = (*description).Markup
				op.Attributes[workitem.SystemDescriptionRendered] =
					rendering.RenderMarkupToHTML(html.EscapeString((*description).Content), (*description).Markup)
			}
		case workitem.SystemCodebase:
			if val != nil {
				op.Attributes[name] = val
			}
		default:
			op.Attributes[name] = val
		}
	}
	if op.Relationships.Assignees == nil {
		op.Relationships.Assignees = &app.RelationGenericList{Data: nil}
	}
	if op.Relationships.Iteration == nil {
		op.Relationships.Iteration = &app.RelationGeneric{Data: nil}
	}
	if op.Relationships.Area == nil {
		op.Relationships.Area = &app.RelationGeneric{Data: nil}
	}
	WorkItemIncludeComments(request, &wi, op)
	WorkItemIncludeChildren(request, &wi, op)
	for _, add := range additional {
		add(request, &wi, op)
	}
	return op
}
func ConvertWorkItem ( request * goa . RequestData , wi workitem . WorkItem , additional ... WorkItemConvertFunc ) * app . WorkItem { selfURL := rest . AbsoluteURL ( request , app . WorkitemHref ( wi . SpaceID . String ( ) , wi . ID ) ) sourceLinkTypesURL := rest . AbsoluteURL ( request , app . WorkitemtypeHref ( wi . SpaceID . String ( ) , wi . Type ) + sourceLinkTypesRouteEnd ) targetLinkTypesURL := rest . AbsoluteURL ( request , app . WorkitemtypeHref ( wi . SpaceID . String ( ) , wi . Type ) + targetLinkTypesRouteEnd ) spaceSelfURL := rest . AbsoluteURL ( request , app . SpaceHref ( wi . SpaceID . String ( ) ) ) witSelfURL := rest . AbsoluteURL ( request , app . WorkitemtypeHref ( wi . SpaceID . String ( ) , wi . Type ) ) op := & app . WorkItem { ID : & wi . ID , Type : APIStringTypeWorkItem , Attributes : map [ string ] interface { } { " " : wi . Version , } , Relationships : & app . WorkItemRelationships { BaseType : & app . RelationBaseType { Data : & app . BaseTypeData { ID : wi . Type , Type : APIStringTypeWorkItemType , } , Links : & app . GenericLinks { Self : & witSelfURL , } , } , Space : app . NewSpaceRelation ( wi . SpaceID , spaceSelfURL ) , } , Links : & app . GenericLinksForWorkItem { Self : & selfURL , SourceLinkTypes : & sourceLinkTypesURL , TargetLinkTypes : & targetLinkTypesURL , } , } for name , val := range wi . Fields { switch name { case workitem . SystemAssignees : if val != nil { valArr := val . ( [ ] interface { } ) op . Relationships . Assignees = & app . RelationGenericList { Data : ConvertUsersSimple ( request , valArr ) , } } case workitem . SystemCreator : if val != nil { valStr := val . ( string ) op . Relationships . Creator = & app . RelationGeneric { Data : ConvertUserSimple ( request , valStr ) , } } case workitem . SystemIteration : if val != nil { valStr := val . ( string ) op . Relationships . Iteration = & app . RelationGeneric { Data : ConvertIterationSimple ( request , valStr ) , } } case workitem . SystemArea : if val != nil { valStr := val . ( string ) op . Relationships . Area = & app . RelationGeneric { Data : ConvertAreaSimple ( request , valStr ) , } } case workitem . SystemTitle : op . Attributes [ name ] = html . EscapeString ( val . ( string ) ) case workitem . SystemDescription : description := rendering . NewMarkupContentFromValue ( val ) if description != nil { op . Attributes [ name ] = ( * description ) . Content op . Attributes [ workitem . SystemDescriptionMarkup ] = ( * description ) . Markup op . Attributes [ workitem . SystemDescriptionRendered ] = rendering . RenderMarkupToHTML ( html . EscapeString ( ( * description ) . Content ) , ( * description ) . Markup ) } case workitem . SystemCodebase : if val != nil { op . Attributes [ name ] = val } default : op . Attributes [ name ] = val } } if op . Relationships . Assignees == nil { op . Relationships . Assignees = & app . RelationGenericList { Data : nil } } if op . Relationships . Iteration == nil { op . Relationships . Iteration = & app . RelationGeneric { Data : nil } } if op . Relationships . Area == nil { op . Relationships . Area = & app . RelationGeneric { Data : nil } } WorkItemIncludeComments ( request , & wi , op ) WorkItemIncludeChildren ( request , & wi , op ) for _ , add := range additional { add ( request , & wi , op ) } return op }
ConvertWorkItem is responsible for converting given WorkItem model object into a
response resource object by jsonapi.org specifications
ConvertWorkItem is responsible for converting given WorkItem model object into a response resource object by jsonapi . org specifications
// construct default values from input WI // Move fields into Relationships or Attributes as needed // TODO: Loop based on WorkItemType and match against Field.Type instead of directly to field value // 'HTML escape' the title to prevent script injection // let's include the rendered description while 'HTML escaping' it to prevent script injection // TODO: Following format is TBD and hence commented out // cb := val.(codebase.CodebaseContent) // urlparams := fmt.Sprintf("/codebase/generate?repo=%s&branch=%s&file=%s&line=%d", cb.Repository, cb.Branch, cb.FileName, cb.LineNumber) // doitURL := rest.AbsoluteURL(request, url.QueryEscape(urlparams)) // op.Links.Doit = &doitURL // Always include Comments Link, but optionally use WorkItemIncludeCommentsAndTotal