Example #1
0
func okResp(a *design.ActionDefinition) map[string]interface{} {
	var ok *design.ResponseDefinition
	for _, resp := range a.Responses {
		if resp.Status == 200 {
			ok = resp
			break
		}
	}
	if ok == nil {
		return nil
	}
	var mt *design.MediaTypeDefinition
	var ok2 bool
	if mt, ok2 = design.Design.MediaTypes[ok.MediaType]; !ok2 {
		return nil
	}
	typeref := codegen.GoTypeRef(mt, 1)
	if strings.HasPrefix(typeref, "*") {
		typeref = "&app." + typeref[1:]
	} else {
		typeref = "app." + typeref
	}
	return map[string]interface{}{
		"Name":             ok.Name,
		"HasMultipleViews": len(mt.Views) > 1,
		"GoType":           codegen.GoNativeType(mt),
		"TypeRef":          typeref,
	}
}
Example #2
0
// join is a code generation helper function that generates a function signature built from
// concatenating the properties (name type) of the given attribute type (assuming it's an object).
func join(att *design.AttributeDefinition) string {
	if att == nil {
		return ""
	}
	obj := att.Type.ToObject()
	elems := make([]string, len(obj))
	i := 0
	for n, a := range obj {
		elems[i] = fmt.Sprintf("%s %s", n, codegen.GoNativeType(a.Type))
		i++
	}
	sort.Strings(elems)
	return strings.Join(elems, ", ")
}
Example #3
0
func okResp(a *design.ActionDefinition, v string) map[string]interface{} {
	var ok *design.ResponseDefinition
	for _, resp := range a.Responses {
		if resp.Status == 200 {
			ok = resp
			break
		}
	}
	if ok == nil {
		return nil
	}
	var mt *design.MediaTypeDefinition
	var ok2 bool
	if mt, ok2 = design.Design.MediaTypes[design.CanonicalIdentifier(ok.MediaType)]; !ok2 {
		return nil
	}
	var pkg string
	if v == "" {
		pkg = TargetPackage
	} else {
		pkg = codegen.VersionPackage(v)
	}
	name := codegen.GoTypeRef(mt, mt.AllRequired(), 1)
	var pointer string
	if strings.HasPrefix(name, "*") {
		name = name[1:]
		pointer = "*"
	}
	typeref := fmt.Sprintf("%s%s.%s", pointer, pkg, name)
	if strings.HasPrefix(typeref, "*") {
		typeref = "&" + typeref[1:]
	}
	return map[string]interface{}{
		"Name":             ok.Name,
		"HasMultipleViews": len(mt.Views) > 1,
		"GoType":           codegen.GoNativeType(mt),
		"TypeRef":          typeref,
	}
}