Add type namespaces

This commit is contained in:
Mathieu Acthernoene 2017-01-10 12:24:06 +01:00
parent dc8e191077
commit 738a68fd4c
3 changed files with 23 additions and 7 deletions

View File

@ -16,7 +16,8 @@ export type TestEnum = {|
export type TestNestedEnum = {|
export type TestMessage$TestNestedEnum = {|
ELEMENT_C?: 0; ELEMENT_C?: 0;
@ -26,7 +27,7 @@ export type TestNestedEnum = {|
export type TestNestedMessage = {| export type TestMessage$TestNestedMessage = {|
s?: string; s?: string;
@ -59,9 +60,9 @@ export type TestMessage = {|
u?: TestEnum; u?: TestEnum;
v?: TestNestedEnum; v?: TestMessage$TestNestedEnum;
w?: Array<TestNestedMessage>; w?: Array<TestMessage$TestNestedMessage>;
|}; |};
@ -69,6 +70,7 @@ export type TestMessage = {|
export type TestNoStreamRequest = {| export type TestNoStreamRequest = {|
message?: TestMessage; message?: TestMessage;
@ -79,6 +81,7 @@ export type TestNoStreamRequest = {|
export type TestNoStreamReply = {| export type TestNoStreamReply = {|
message?: TestMessage; message?: TestMessage;
@ -91,6 +94,7 @@ export type TestNoStreamReply = {|
export type TestStreamRequestRequest = {| export type TestStreamRequestRequest = {|
message?: TestMessage; message?: TestMessage;
@ -101,6 +105,7 @@ export type TestStreamRequestRequest = {|
export type TestStreamRequestReply = {| export type TestStreamRequestReply = {|
message?: TestMessage; message?: TestMessage;
@ -113,6 +118,7 @@ export type TestStreamRequestReply = {|
export type TestStreamReplyRequest = {| export type TestStreamReplyRequest = {|
message?: TestMessage; message?: TestMessage;
@ -123,6 +129,7 @@ export type TestStreamReplyRequest = {|
export type TestStreamReplyReply = {| export type TestStreamReplyReply = {|
message?: TestMessage; message?: TestMessage;
@ -135,6 +142,7 @@ export type TestStreamReplyReply = {|
export type TestStreamBothRequest = {| export type TestStreamBothRequest = {|
message?: TestMessage; message?: TestMessage;
@ -145,6 +153,7 @@ export type TestStreamBothRequest = {|
export type TestStreamBothReply = {| export type TestStreamBothReply = {|
message?: TestMessage; message?: TestMessage;

View File

@ -13,8 +13,9 @@ export type {{.Name}} = {|
{{end}} {{end}}
{{range .File.MessageType}} {{range .File.MessageType}}
{{$MessageType := .Name}}
{{range .EnumType}} {{range .EnumType}}
export type {{.Name}} = {| export type {{$MessageType}}${{.Name}} = {|
{{range .Value}} {{range .Value}}
{{.Name}}?: {{.Number}}; {{.Name}}?: {{.Number}};
{{end}} {{end}}
@ -22,7 +23,7 @@ export type {{.Name}} = {|
{{end}} {{end}}
{{range .NestedType}} {{range .NestedType}}
export type {{.Name}} = {| export type {{$MessageType}}${{.Name}} = {|
{{range .Field}} {{range .Field}}
{{.Name}}?: {{. | jsType}}; {{.Name}}?: {{. | jsType}};
{{end}} {{end}}

View File

@ -150,7 +150,7 @@ func jsType(f *descriptor.FieldDescriptorProto) string {
switch *f.Type { switch *f.Type {
case descriptor.FieldDescriptorProto_TYPE_MESSAGE, case descriptor.FieldDescriptorProto_TYPE_MESSAGE,
descriptor.FieldDescriptorProto_TYPE_ENUM: descriptor.FieldDescriptorProto_TYPE_ENUM:
return fmt.Sprintf(template, shortType(*f.TypeName)) return fmt.Sprintf(template, namespacedFlowType(*f.TypeName))
case descriptor.FieldDescriptorProto_TYPE_DOUBLE, case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
descriptor.FieldDescriptorProto_TYPE_FLOAT, descriptor.FieldDescriptorProto_TYPE_FLOAT,
descriptor.FieldDescriptorProto_TYPE_INT64, descriptor.FieldDescriptorProto_TYPE_INT64,
@ -180,6 +180,12 @@ func shortType(s string) string {
return t[len(t)-1] return t[len(t)-1]
} }
func namespacedFlowType(s string) string {
trimmed := strings.TrimLeft(s, ".")
splitted := strings.Split(trimmed, ".")
return strings.Join(splitted[1:], "$")
}
func httpPath(m *descriptor.MethodDescriptorProto) string { func httpPath(m *descriptor.MethodDescriptorProto) string {
ext, err := proto.GetExtension(m.Options, options.E_Http) ext, err := proto.GetExtension(m.Options, options.E_Http)