diff --git a/helpers.go b/helpers.go index 2f3f1aa..065f9c4 100644 --- a/helpers.go +++ b/helpers.go @@ -67,6 +67,7 @@ var ProtoHelpersFuncMap = template.FuncMap{ "isFieldMessage": isFieldMessage, "isFieldRepeated": isFieldRepeated, "goType": goType, + "jsType": jsType, "httpVerb": httpVerb, "httpPath": httpPath, } @@ -139,6 +140,35 @@ func goType(pkg string, f *descriptor.FieldDescriptorProto) string { } } +func jsType(f *descriptor.FieldDescriptorProto) string { + switch *f.Type { + case descriptor.FieldDescriptorProto_TYPE_DOUBLE: + return "number" + case descriptor.FieldDescriptorProto_TYPE_FLOAT: + return "number" + case descriptor.FieldDescriptorProto_TYPE_INT64: + return "number" + case descriptor.FieldDescriptorProto_TYPE_UINT64: + return "number" + case descriptor.FieldDescriptorProto_TYPE_INT32: + return "number" + case descriptor.FieldDescriptorProto_TYPE_BOOL: + return "boolean" + case descriptor.FieldDescriptorProto_TYPE_STRING: + return "string" + case descriptor.FieldDescriptorProto_TYPE_MESSAGE: + return "message" + case descriptor.FieldDescriptorProto_TYPE_BYTES: + return "number" + case descriptor.FieldDescriptorProto_TYPE_UINT32: + return "number" + case descriptor.FieldDescriptorProto_TYPE_ENUM: + return "message" + default: + return "object" + } +} + func shortType(s string) string { t := strings.Split(s, ".") return t[len(t)-1]