Beispiel #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[design.CanonicalIdentifier(ok.MediaType)]; !ok2 {
		return nil
	}
	name := codegen.GoTypeRef(mt, mt.AllRequired(), 1, false)
	var pointer string
	if strings.HasPrefix(name, "*") {
		name = name[1:]
		pointer = "*"
	}
	typeref := fmt.Sprintf("%s%s.%s", pointer, TargetPackage, name)
	if strings.HasPrefix(typeref, "*") {
		typeref = "&" + typeref[1:]
	}
	return map[string]interface{}{
		"Name":    ok.Name,
		"GoType":  codegen.GoNativeType(mt),
		"TypeRef": typeref,
	}
}
Beispiel #2
0
func typeName(mt *design.MediaTypeDefinition) string {
	name := codegen.GoTypeName(mt, mt.AllRequired(), 1, false)
	if mt.IsBuiltIn() {
		return strings.Split(name, ".")[1]
	}
	return name
}
Beispiel #3
0
func typeName(mt *design.MediaTypeDefinition) string {
	if mt.IsError() {
		return "ErrorResponse"
	}
	return codegen.GoTypeName(mt, mt.AllRequired(), 1, false)
}