当前位置: 首页>>代码示例>>Golang>>正文


Golang rdl.TypeRegistry类代码示例

本文整理汇总了Golang中github.com/ardielle/ardielle-go/rdl.TypeRegistry的典型用法代码示例。如果您正苦于以下问题:Golang TypeRegistry类的具体用法?Golang TypeRegistry怎么用?Golang TypeRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TypeRegistry类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: javaGenerateStructTypeConstructor

func javaGenerateStructTypeConstructor(reg rdl.TypeRegistry, t *rdl.StructTypeDef) string {
	s := fmt.Sprintf("    sb.structType(%q", t.Name)
	if t.Type != "Struct" {
		s += fmt.Sprintf(", %q)", t.Type)
	} else {
		s += ")"
	}
	if t.Comment != "" {
		s += fmt.Sprintf("\n            .comment(%q)", t.Comment)
	}
	for _, f := range t.Fields {
		if f.Keys != "" {
			fkeys := string(f.Keys)   //javaType(reg, f.Keys, false, "", "")
			fitems := string(f.Items) //javaType(reg, f.Items, false, "", "")
			s += fmt.Sprintf("\n            .mapField(%q, %q, %q, %v, %q)", f.Name, fkeys, fitems, f.Optional, f.Comment)
		} else if f.Items != "" {
			fitems := string(f.Items) //javaType(reg, f.Items, false, "", "")
			s += fmt.Sprintf("\n            .arrayField(%q, %q, %v, %q)", f.Name, fitems, f.Optional, f.Comment)
		} else {
			ftype := string(f.Type) //javaType(reg, f.Type, f.Optional, "", "")
			if f.Default != nil {
				ft := reg.FindType(f.Type)
				ss := "null"
				if ft != nil {
					ss = javaLiteral(ft, f.Default)
				}
				s += fmt.Sprintf("\n            .field(%q, %q, %v, %q, %s)", f.Name, ftype, false, f.Comment, ss)
			} else {
				s += fmt.Sprintf("\n            .field(%q, %q, %v, %q)", f.Name, ftype, f.Optional, f.Comment)
			}
		}
	}
	return s + ";"
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:34,代码来源:java-schema.go

示例2: annotate

func annotate(registry rdl.TypeRegistry, typename rdl.TypeRef) string {
	t := registry.FindType(typename)
	if t != nil {
		tName, tType, _ := rdl.TypeInfo(t)
		if tType != rdl.TypeRef(tName) {
			return "[" + string(typename) + "](#" + strings.ToLower(string(typename)) + ")"
		}
	}
	return string(typename)
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:10,代码来源:main.go

示例3: typeStack

func typeStack(registry rdl.TypeRegistry, typeDef *rdl.Type) []*rdl.Type {
	var types []*rdl.Type
	types = append(types, typeDef)
	tName, tType, _ := rdl.TypeInfo(typeDef)
	for tName != rdl.TypeName(tType) {
		supertype := registry.FindType(tType)
		types = append(types, supertype)
		tName, tType, _ = rdl.TypeInfo(supertype)
	}
	return types
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:11,代码来源:main.go

示例4: addFields

func addFields(reg rdl.TypeRegistry, dst []*rdl.StructFieldDef, t *rdl.Type) []*rdl.StructFieldDef {
	switch t.Variant {
	case rdl.TypeVariantStructTypeDef:
		st := t.StructTypeDef
		if st.Type != "Struct" {
			dst = addFields(reg, dst, reg.FindType(st.Type))
		}
		for _, f := range st.Fields {
			dst = append(dst, f)
		}
	}
	return dst
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:13,代码来源:go-util.go

示例5: explodeURL

func explodeURL(reg rdl.TypeRegistry, r *rdl.Resource) string {
	path := r.Path
	params := ""
	delim := ""
	for _, v := range r.Inputs {
		k := v.Name
		gk := goName(string(k))
		if v.PathParam {
			//
			if v.Type == "String" {
				path = strings.Replace(path, "{"+string(k)+"}", "\" + "+gk+" + \"", -1)
			} else {
				path = strings.Replace(path, "{"+string(k)+"}", "\" + fmt.Sprint("+gk+") + \"", -1)
			}
		} else if v.QueryParam != "" {
			qp := v.QueryParam
			item := ""
			if reg.IsArrayTypeName(v.Type) {
				item = "encodeListParam(\"" + qp + "\"," + gk + ")"
			} else {
				baseType := reg.BaseTypeName(v.Type)
				if v.Optional && baseType != "String" {
					item = "encodeOptional" + string(baseType) + "Param(\"" + qp + "\", " + gk + ")"
				} else {
					def := goLiteral(v.Default, string(baseType))
					if baseType == "Enum" {
						def = "\"" + def + "\""
						item = "encodeStringParam(\"" + qp + "\", " + gk + ".String(), " + def + ")"
					} else {
						item = "encode" + string(baseType) + "Param(\"" + qp + "\", " + strings.ToLower(string(baseType)) + "(" + gk + "), " + def + ")"
					}
				}
			}
			params += delim + item
			delim = ", "
		}
	}
	path = "\"" + path
	if strings.HasSuffix(path, " + \"") {
		path = path[0 : len(path)-4]
	} else {
		path += "\""
	}
	if params != "" {
		path = path + " + encodeParams(" + params + ")"
	}
	return path
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:48,代码来源:go-client.go

示例6: generateJavaType

func generateJavaType(banner string, schema *rdl.Schema, registry rdl.TypeRegistry, outdir string, t *rdl.Type, ns string) error {
	tName, _, _ := rdl.TypeInfo(t)
	bt := registry.BaseType(t)
	switch bt {
	case rdl.BaseTypeStruct:
	case rdl.BaseTypeUnion:
	case rdl.BaseTypeEnum:
	default:
		return nil
	}
	cName := capitalize(string(tName))
	out, file, _, err := outputWriter(outdir, cName, ".java")
	if err != nil {
		return err
	}
	if file != nil {
		defer file.Close()
	}
	gen := &javaModelGenerator{registry, schema, string(tName), out, nil, ns, true}
	gen.emitHeader(banner, ns, bt, t)
	switch bt {
	case rdl.BaseTypeStruct:
		gen.emit("\n")
		gen.emitStruct(t, cName)
	case rdl.BaseTypeUnion:
		gen.emit("\n")
		gen.emitUnion(t)
	case rdl.BaseTypeArray:
		gen.emit("\n")
		gen.emitArray(t)
	case rdl.BaseTypeEnum:
		gen.emit("\n")
		gen.emitTypeComment(t)
		gen.emitEnum(t)
	}
	out.Flush()
	return gen.err
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:38,代码来源:java-model.go

示例7: makeSwaggerTypeRef

func makeSwaggerTypeRef(reg rdl.TypeRegistry, itemTypeName rdl.TypeRef) (string, string, *SwaggerType) {
	itype := string(itemTypeName)
	switch reg.FindBaseType(itemTypeName) {
	case rdl.BaseTypeInt8:
		return "string", "byte", nil
	case rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64:
		return "integer", strings.ToLower(itype), nil
	case rdl.BaseTypeFloat32:
		return "number", "float", nil
	case rdl.BaseTypeFloat64:
		return "number", "double", nil
	case rdl.BaseTypeString:
		return "string", "", nil
	case rdl.BaseTypeTimestamp:
		return "string", "date-time", nil
	case rdl.BaseTypeUUID, rdl.BaseTypeSymbol:
		return "string", strings.ToLower(itype), nil
	default:
		s := new(SwaggerType)
		s.Ref = "#/definitions/" + itype
		return "", "", s
	}
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:23,代码来源:main.go

示例8: javaGenerateResourceConstructor

func javaGenerateResourceConstructor(reg rdl.TypeRegistry, rez *rdl.Resource) string {
	rTypeName := rez.Type
	if rez.Method == "PUT" || rez.Method == "POST" {
		for _, ri := range rez.Inputs {
			if !ri.PathParam && ri.QueryParam == "" && ri.Header == "" {
				rTypeName = ri.Type
				break
			}
		}
	}
	s := fmt.Sprintf("    sb.resource(%q, %q, %q)", rTypeName, rez.Method, rez.Path)
	if rez.Comment != "" {
		s += fmt.Sprintf("\n            .comment(%q)", rez.Comment)
	}
	for _, ri := range rez.Inputs {
		def := "null"
		if ri.Default != nil {
			ft := reg.FindType(ri.Type)
			if ft != nil {
				def = javaLiteral(ft, ri.Default)
			}
		}
		if ri.PathParam {
			s += fmt.Sprintf("\n            .pathParam(%q, %q, %q)", ri.Name, ri.Type, ri.Comment)
		} else if ri.QueryParam != "" {
			s += fmt.Sprintf("\n            .queryParam(%q, %q, %q, %s, %q)", ri.QueryParam, ri.Name, ri.Type, def, ri.Comment)
		} else if ri.Header != "" {
			s += fmt.Sprintf("\n            .headerParam(%q, %q, %q, %s, %q)", ri.Header, ri.Name, ri.Type, def, ri.Comment)
		} else {
			s += fmt.Sprintf("\n            .input(%q, %q, %q)", ri.Name, ri.Type, ri.Comment)
		}
	}
	for _, ro := range rez.Outputs {
		s += fmt.Sprintf("\n            .output(%q, %q, %q, %q)", ro.Header, ro.Name, ro.Type, ro.Comment)
	}
	if rez.Auth != nil {
		if rez.Auth.Domain != "" {
			s += fmt.Sprintf("\n            .auth(%q, %q, %v, %q)", rez.Auth.Action, rez.Auth.Resource, rez.Auth.Authenticate, rez.Auth.Domain)
		} else if rez.Auth.Authenticate {
			s += fmt.Sprintf("\n            .auth(%q, %q, true)", rez.Auth.Action, rez.Auth.Resource)
		} else {
			s += fmt.Sprintf("\n            .auth(%q, %q)", rez.Auth.Action, rez.Auth.Resource)
		}
	}
	s += fmt.Sprintf("\n            .expected(%q)", rez.Expected)
	//build a sorted order for the exceptions, to make them predictable. Go randomizes the order otherwise.
	var syms []string
	for sym, _ := range rez.Exceptions {
		syms = append(syms, sym)
	}
	sort.Strings(syms)
	for _, sym := range syms {
		re := rez.Exceptions[sym]
		s += fmt.Sprintf("\n            .exception(%q, %q, %q)\n", sym, re.Type, re.Comment)
	}
	if rez.Async != nil {
		if *rez.Async {
			s += fmt.Sprintf("\n            .async()\n")
		}
	}
	return s + ";"
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:62,代码来源:java-schema.go

示例9: goParamInit

func goParamInit(reg rdl.TypeRegistry, qname string, pname string, ptype rdl.TypeRef, pdefault interface{}, poptional bool, precise bool, prefixEnums bool) string {
	s := ""
	gtype := goType(reg, ptype, false, "", "", precise, true)
	switch gtype {
	/*
		case "string":
			if pdefault == nil {
				s += "\t" + pname + " := rdl.OptionalStringParam(request, \"" + qname + "\")\n"
			} else {
				def := fmt.Sprintf("%v", pdefault)
				s += "\tvar " + pname + "Optional " + gtype + " = " + def + "\n"
				s += "\t" + pname + ", _ := rdl.StringParam(request, \"" + qname + "\", " + pname + "Optional)\n"
			}
		case "bool":
			if pdefault == nil {
				s += "\t" + pname + ", err := rdl.OptionalBoolParam(request, \"" + qname + "\")\n"
				s += "\tif err != nil {\n"
				s += "\t\trdl.JSONResponse(writer, 400, err)\n"
				s += "\t\treturn\n"
				s += "\t}\n"
			} else {
				def := fmt.Sprintf("%v", pdefault)
				s += "\tvar " + pname + "Optional " + gtype + " = " + def + "\n"
				s += "\t" + pname + " := rdl.BoolParam(request, \"" + qname + "\", " + pname + "Optional)\n"
			}
		case "int32", "int64", "int16", "int8":
			if pdefault == nil {
				s += "\t" + pname + ", err := rdl.OptionalInt32Param(request, \"" + qname + "\")\n"
				s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
			} else {
				def := "0"
				switch v := pdefault.(type) {
				case float64:
					def = fmt.Sprintf("%v", v)
				default:
					fmt.Println("fix me:", pdefault)
					panic("fix me")
				}
				if precise {
					s += "\t" + pname + "_, err := rdl.Int32Param(request, \"" + qname + "\", " + def + ")\n"
				} else {
					s += "\t" + pname + ", err := rdl.Int32Param(request, \"" + qname + "\", " + def + ")\n"
				}
				s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
				if precise {
					s += "\t" + pname + " := " + gtype + "(" + pname + "_)\n"
				}
			}
	*/
	default:
		t := reg.FindType(ptype)
		bt := reg.BaseType(t)
		switch bt {
		case rdl.BaseTypeString:
			if pdefault == nil {
				if precise && gtype != "string" {
					s += "\t" + pname + " := " + gtype + "(rdl.OptionalStringParam(request, \"" + qname + "\"))\n"
				} else {
					s += "\t" + pname + " := rdl.OptionalStringParam(request, \"" + qname + "\")\n"
				}
			} else {
				def := fmt.Sprintf("%q", pdefault)
				if precise && gtype != "string" {
					s += "\t" + pname + "Val, _ := rdl.StringParam(request, \"" + qname + "\", " + def + ")\n"
					s += "\t" + pname + " := " + gtype + "(" + pname + "Val)\n"
				} else {
					s += "\t" + pname + ", _ := rdl.StringParam(request, \"" + qname + "\", " + def + ")\n"
				}
			}
		case rdl.BaseTypeInt32, rdl.BaseTypeInt16, rdl.BaseTypeInt8, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
			stype := fmt.Sprint(bt)
			if pdefault == nil {
				s += "\t" + pname + ", err := rdl.Optional" + stype + "Param(request, \"" + qname + "\")\n" //!
				s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
			} else {
				def := "0"
				switch v := pdefault.(type) {
				case float64:
					def = fmt.Sprintf("%v", v)
				default:
					fmt.Println("fix me:", pdefault)
					panic("fix me")
				}
				if precise {
					s += "\t" + pname + "_, err := rdl." + stype + "Param(request, \"" + qname + "\", " + def + ")\n"
				} else {
					s += "\t" + pname + ", err := rdl." + stype + "Param(request, \"" + qname + "\", " + def + ")\n"
				}
				s += "\tif err != nil {\n\t\trdl.JSONResponse(writer, 400, err)\n\t\treturn\n\t}\n"
				if precise {
					s += "\t" + pname + " := " + gtype + "(" + pname + "_)\n"
				}
			}
		case rdl.BaseTypeBool:
			if pdefault == nil {
				s += "\t" + pname + ", err := rdl.OptionalBoolParam(request, \"" + qname + "\")\n"
				s += "\tif err != nil {\n"
				s += "\t\trdl.JSONResponse(writer, 400, err)\n"
				s += "\t\treturn\n"
				s += "\t}\n"
//.........这里部分代码省略.........
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:101,代码来源:go-server.go

示例10: goHandlerBody

func goHandlerBody(reg rdl.TypeRegistry, name string, r *rdl.Resource, precise bool, prefixEnums bool) string {
	s := ""
	var fargs []string
	bodyName := ""
	for _, in := range r.Inputs {
		name := "arg" + capitalize(string(in.Name))
		if in.QueryParam != "" {
			qname := in.QueryParam
			if in.Optional || in.Default != nil {
				s += goParamInit(reg, qname, name, in.Type, in.Default, in.Optional, precise, prefixEnums)
			} else {
				log.Println("RDL error: queryparam must either be optional or have a default value")
			}
			fargs = append(fargs, name)
		} else if in.PathParam {
			bt := reg.BaseTypeName(in.Type)
			switch bt {
			case "Enum":
				s += fmt.Sprintf("\t%s := New%s(context.Params[%q])\n", name, in.Type, in.Name)
			case "Int32", "Int64", "Int16", "Int8":
				if precise {
					s += fmt.Sprintf("\t%s := %s(intFromString(context.Params[%q]))\n", name, in.Type, in.Name)
				} else {
					s += fmt.Sprintf("\t%s := intFromString(context.Params[%q])\n", name, in.Name)
				}
			case "Float32", "Float64":
				if precise {
					s += fmt.Sprintf("\t%s := %s(floatFromString(context.Params[%q]))\n", name, in.Type, in.Name)
				} else {
					s += fmt.Sprintf("\t%s := floatFromString(context.Params[%q])\n", name, in.Name)
				}
			default:
				if precise && strings.ToLower(string(in.Type)) != "string" {
					s += fmt.Sprintf("\t%s := %s(context.Params[%q])\n", name, in.Type, in.Name)
				} else {
					s += fmt.Sprintf("\t%s := context.Params[%q]\n", name, in.Name)
				}
			}
			fargs = append(fargs, name)
		} else if in.Header != "" {
			hname := in.Header
			def := ""
			if in.Default != nil {
				switch v := in.Default.(type) {
				case string:
					def = fmt.Sprintf("%q", v)
				default:
					panic(fmt.Sprintf("implement me, default value: %v", in))
				}
				s += "\t" + name + "Optional := " + def + "\n"
				s += fmt.Sprintf("\t%s := rdl.HeaderParam(request, %q, %sOptional)\n", name, hname, name)
			} else if in.Optional {
				s += fmt.Sprintf("\t%s := rdl.OptionalHeaderParam(request, %q)\n", name, hname)
			} else {
				s += fmt.Sprintf("\t%s := rdl.HeaderParam(request, %q, \"\")\n", name, hname)
			}
			fargs = append(fargs, name)
		} else {
			bodyName = name
			s += "\tbody, oserr := ioutil.ReadAll(request.Body)\n"
			s += "\tif oserr != nil {\n"
			s += "\t\trdl.JSONResponse(writer, http.StatusBadRequest, rdl.ResourceError{Code: http.StatusBadRequest, Message: \"Bad request: \" + oserr.Error()})\n"
			s += "\t\treturn\n"
			s += "\t}\n"
			pgtype := goType(reg, in.Type, false, "", "", precise, true)
			s += "\tvar " + bodyName + " " + pgtype + "\n"
			s += "\toserr = json.Unmarshal(body, &" + bodyName + ")\n"
			s += "\tif oserr != nil {\n"
			s += "\t\trdl.JSONResponse(writer, http.StatusBadRequest, rdl.ResourceError{Code: http.StatusBadRequest, Message: \"Bad request: \" + oserr.Error()})\n"
			s += "\t\treturn\n"
			s += "\t}\n"
			fargs = append(fargs, bodyName)
		}
	}
	if r.Auth != nil {
		if r.Auth.Authenticate {
			s += authenticateTemplate
		} else if r.Auth.Action != "" && r.Auth.Resource != "" {
			resource := r.Auth.Resource
			i := strings.Index(resource, "{")
			for i >= 0 {
				j := strings.Index(resource[i:], "}")
				if j < 0 {
					break
				}
				j += i
				val := "string(arg" + capitalize(resource[i+1:j]) + ")"
				resource = resource[0:i] + "\" + " + val + " + \"" + resource[j+1:]
				i = strings.Index(resource, "{")
			}
			resource = "\"" + resource
			if strings.HasSuffix(resource, "+ \"") {
				resource = resource[0 : len(resource)-3]
			} else {
				resource = resource + "\""
			}
			if strings.HasPrefix(resource, "\"\" + ") {
				resource = resource[5:]
			}
			s += fmt.Sprintf(authorizeTemplate, r.Auth.Action, resource)
//.........这里部分代码省略.........
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:101,代码来源:go-server.go

示例11: javaType

func javaType(reg rdl.TypeRegistry, rdlType rdl.TypeRef, optional bool, items rdl.TypeRef, keys rdl.TypeRef) string {
	t := reg.FindType(rdlType)
	if t == nil || t.Variant == 0 {
		panic("Cannot find type '" + rdlType + "'")
	}
	bt := reg.BaseType(t)
	switch bt {
	case rdl.BaseTypeAny:
		return "Object"
	case rdl.BaseTypeString:
		return "String"
	case rdl.BaseTypeSymbol, rdl.BaseTypeTimestamp, rdl.BaseTypeUUID:
		return string(rdlType)
	case rdl.BaseTypeBool:
		if optional {
			return "Boolean"
		}
		return "boolean"
	case rdl.BaseTypeInt8:
		if optional {
			return "Byte"
		}
		return "byte"
	case rdl.BaseTypeInt16:
		if optional {
			return "Short"
		}
		return "short"
	case rdl.BaseTypeInt32:
		if optional {
			return "Integer"
		}
		return "int"
	case rdl.BaseTypeInt64:
		if optional {
			return "Long"
		}
		return "long"
	case rdl.BaseTypeFloat32:
		if optional {
			return "Float"
		}
		return "float"
	case rdl.BaseTypeFloat64:
		if optional {
			return "Double"
		}
		return "double"
	case rdl.BaseTypeArray:
		i := rdl.TypeRef("Any")
		switch t.Variant {
		case rdl.TypeVariantArrayTypeDef:
			i = t.ArrayTypeDef.Items
		default:
			if items != "" && items != "Any" {
				i = items
			}
		}
		gitems := javaType(reg, rdl.TypeRef(i), false, "", "")
		//return gitems + "[]" //if arrays, not lists
		return "List<" + gitems + ">"
	case rdl.BaseTypeMap:
		k := rdl.TypeRef("Any")
		i := rdl.TypeRef("Any")
		switch t.Variant {
		case rdl.TypeVariantMapTypeDef:
			k = t.MapTypeDef.Keys
			i = t.MapTypeDef.Items
		default:
			if keys != "" && keys != "Any" {
				k = keys
			}
			if items != "" && items != "Any" {
				i = items
			}
		}
		gkeys := javaType(reg, k, false, "", "")
		gitems := javaType(reg, i, false, "", "")
		return "Map<" + gkeys + ", " + gitems + ">"
	case rdl.BaseTypeStruct:
		if strings.HasPrefix(string(rdlType), "rdl.") {
			return string(rdlType)[4:]
		}
		switch t.Variant {
		case rdl.TypeVariantStructTypeDef:
			if t.StructTypeDef.Name == "Struct" {
				return "Object"
			}
		}
		return string(rdlType)
	default:
		return string(rdlType)
	}
}
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:94,代码来源:java-model.go

示例12: goType

func goType(reg rdl.TypeRegistry, rdlType rdl.TypeRef, optional bool, items rdl.TypeRef, keys rdl.TypeRef, precise bool, reference bool) string {
	rdlPrefix := "rdl."
	if reg.Name() == "rdl" {
		rdlPrefix = ""
	}
	cleanType := string(rdlType)
	if !strings.HasPrefix(cleanType, "rdl.") {
		cleanType = capitalize(strings.Replace(string(rdlType), ".", "_", -1))
	}
	prefix := ""
	if optional {
		prefix = "*"
	}
	t := reg.FindType(rdlType)
	if t.Variant == 0 {
		panic("Cannot find type '" + rdlType + "'")
	}
	lrdlType := strings.ToLower(string(rdlType))
	if precise {
		switch lrdlType {
		case "string":
			return "string"
		case "symbol":
			return rdlPrefix + "Symbol"
		case "bool", "int32", "int64", "int16", "int8", "float64", "float32":
			return prefix + strings.ToLower(cleanType)
		default:
			bt := reg.BaseType(t)
			switch bt {
			case rdl.BaseTypeString, rdl.BaseTypeSymbol:
				return cleanType
			case rdl.BaseTypeInt8, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64, rdl.BaseTypeBool:

				return prefix + cleanType
			case rdl.BaseTypeTimestamp, rdl.BaseTypeUUID:
				fullTypeName := rdlPrefix + cleanType
				return prefix + fullTypeName
			default:
				if lrdlType == "struct" {
					fullTypeName := rdlPrefix + cleanType
					return prefix + fullTypeName
				}
			}
		}
	} else {
		switch lrdlType {
		case "timestamp":
			return prefix + rdlPrefix + "Timestamp"
		case "uuid":
			return prefix + rdlPrefix + "UUID"
		case "struct":
			return prefix + rdlPrefix + "Struct"
		}
	}
	bt := reg.BaseType(t)
	switch bt {
	case rdl.BaseTypeAny:
		return "interface{}"
	case rdl.BaseTypeString:
		return "string"
	case rdl.BaseTypeSymbol:
		return rdlPrefix + "Symbol"
	case rdl.BaseTypeBool:
		return prefix + "bool"
	case rdl.BaseTypeInt8, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
		return prefix + strings.ToLower(bt.String())
	case rdl.BaseTypeArray:
		if reference {
			name := "Array"
			if t.ArrayTypeDef != nil {
				name = string(t.ArrayTypeDef.Name)
			}
			if name != "Array" {
				return name
			}
		}
		i := rdl.TypeRef("Any")
		switch t.Variant {
		case rdl.TypeVariantArrayTypeDef:
			i = t.ArrayTypeDef.Items
		default:
			if items != "" {
				i = items
			}
		}
		gitems := goType(reg, i, false, "", "", precise, reference)
		return "[]" + gitems
	case rdl.BaseTypeMap:
		if reference {
			//we check if we have defined a type, i.e. the type name is not "Map"
			name := rdl.TypeName("Map")
			if t.MapTypeDef != nil {
				name = t.MapTypeDef.Name
			} else if t.AliasTypeDef != nil {
				name = t.AliasTypeDef.Name
			}
			if name != "Map" {
				return string(name)
			}
		}
//.........这里部分代码省略.........
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:101,代码来源:go-model.go

示例13: makeSwaggerTypeDef

func makeSwaggerTypeDef(reg rdl.TypeRegistry, t *rdl.Type) *SwaggerType {
	st := new(SwaggerType)
	bt := reg.BaseType(t)
	switch t.Variant {
	case rdl.TypeVariantStructTypeDef:
		typedef := t.StructTypeDef
		st.Description = typedef.Comment
		props := make(map[string]*SwaggerType)
		var required []string
		if len(typedef.Fields) > 0 {
			for _, f := range typedef.Fields {
				if f.Optional {
					required = append(required, string(f.Name))
				}
				ft := reg.FindType(f.Type)
				fbt := reg.BaseType(ft)
				prop := new(SwaggerType)
				prop.Description = f.Comment
				switch fbt {
				case rdl.BaseTypeArray:
					prop.Type = "array"
					if f.Items != "" {
						fitems := string(f.Items)
						items := new(SwaggerType)
						switch fitems {
						case "String":
							items.Type = strings.ToLower(fitems)
						case "Int32", "Int64", "Int16":
							items.Type = "integer"
							items.Format = strings.ToLower(fitems)
						default:
							items.Ref = "#/definitions/" + fitems
						}
						prop.Items = items
					}
				case rdl.BaseTypeString:
					prop.Type = strings.ToLower(fbt.String())
				case rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeInt16:
					prop.Type = "integer"
					prop.Format = strings.ToLower(fbt.String())
				case rdl.BaseTypeStruct:
					prop.Type = "#/definitions/" + string(f.Type)
				case rdl.BaseTypeMap:
					prop.Type = "object"
					if f.Items != "" {
						fitems := string(f.Items)
						items := new(SwaggerType)
						switch f.Items {
						case "String":
							items.Type = strings.ToLower(fitems)
						case "Int32", "Int64", "Int16":
							items.Type = "integer"
							items.Format = strings.ToLower(fitems)
						default:
							items.Ref = "#/definitions/" + fitems
						}
						prop.AdditionalProperties = items
					}
				default:
					prop.Type = "_" + string(f.Type) + "_" //!
				}
				props[string(f.Name)] = prop
			}
		}
		st.Properties = props
		if len(required) > 0 {
			st.Required = required
		}
	case rdl.TypeVariantArrayTypeDef:
		typedef := t.ArrayTypeDef
		st.Type = bt.String()
		if typedef.Items != "Any" {
			items := new(SwaggerType)
			switch reg.FindBaseType(typedef.Items) {
			case rdl.BaseTypeString:
				items.Type = strings.ToLower(string(typedef.Items))
			case rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeInt16:
				items.Type = "integer"
				items.Format = strings.ToLower(string(typedef.Items))
			default:
				items.Ref = "#/definitions/" + string(typedef.Items)
			}
			st.Items = items
		}
	case rdl.TypeVariantEnumTypeDef:
		typedef := t.EnumTypeDef
		var tmp []string
		for _, el := range typedef.Elements {
			tmp = append(tmp, string(el.Symbol))
		}
		st.Enum = tmp
	case rdl.TypeVariantUnionTypeDef:
		typedef := t.UnionTypeDef
		fmt.Println("[" + typedef.Name + ": Swagger doesn't support unions]")
	default:
		switch bt {
		case rdl.BaseTypeString, rdl.BaseTypeInt16, rdl.BaseTypeInt32, rdl.BaseTypeInt64, rdl.BaseTypeFloat32, rdl.BaseTypeFloat64:
			return nil
		default:
			panic(fmt.Sprintf("whoops: %v", t))
//.........这里部分代码省略.........
开发者ID:dmitris,项目名称:ardielle-tools,代码行数:101,代码来源:main.go


注:本文中的github.com/ardielle/ardielle-go/rdl.TypeRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。