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

View File

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

View File

@ -150,7 +150,7 @@ func jsType(f *descriptor.FieldDescriptorProto) string {
switch *f.Type {
case descriptor.FieldDescriptorProto_TYPE_MESSAGE,
descriptor.FieldDescriptorProto_TYPE_ENUM:
return fmt.Sprintf(template, shortType(*f.TypeName))
return fmt.Sprintf(template, namespacedFlowType(*f.TypeName))
case descriptor.FieldDescriptorProto_TYPE_DOUBLE,
descriptor.FieldDescriptorProto_TYPE_FLOAT,
descriptor.FieldDescriptorProto_TYPE_INT64,
@ -180,6 +180,12 @@ func shortType(s string) string {
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 {
ext, err := proto.GetExtension(m.Options, options.E_Http)