@@ -60,11 +60,12 @@ func (b *contentBuilder) getFieldType(field *descriptorpb.FieldDescriptorProto)
6060 return strings .ToLower (strings .TrimPrefix (field .GetType ().String (), "TYPE_" )), ""
6161 }
6262 fullMessageName := field .GetTypeName ()
63- wkt := wktMapping [fullMessageName ]
64- if b .messageEncoding == "json" && wkt != "" {
65- return wkt , ""
63+ if b .messageEncoding == "json" {
64+ if wkt , ok := wktMapping [fullMessageName ]; ok {
65+ return wkt , ""
66+ }
6667 }
67- return getLocalName (fullMessageName ), fullMessageName
68+ return b . getLocalName (fullMessageName ), fullMessageName
6869}
6970
7071func (b * contentBuilder ) getLabelPrefix (label descriptorpb.FieldDescriptorProto_Label ) string {
@@ -90,21 +91,29 @@ func (b *contentBuilder) payDebts(debts []string, level int) {
9091func (b * contentBuilder ) payDebt (debt string , level int ) {
9192 message := b .messageTypes [debt ]
9293 defer func (originalName * string ) { message .Name = originalName }(message .Name )
93- localName := getLocalName (debt )
94+ localName := b . getLocalName (debt )
9495 message .Name = & localName
9596 b .output .WriteString ("\n " )
9697 b .buildMessage (message , level )
9798}
9899
99- func buildIndent (level int ) string {
100- return strings .Repeat (" " , level )
101- }
102-
103100var localNamePattern = regexp .MustCompile (`\..` )
104101
105- func getLocalName (fullMessageName string ) string {
102+ func (b * contentBuilder ) getLocalName (fullMessageName string ) string {
103+ if b .isNestedType (fullMessageName ) {
104+ return fullMessageName [strings .LastIndexByte (fullMessageName , '.' )+ 1 :]
105+ }
106106 return localNamePattern .ReplaceAllStringFunc (
107107 fullMessageName ,
108108 func (s string ) string { return strings .ToUpper (s [1 :]) },
109109 )
110110}
111+
112+ func (b * contentBuilder ) isNestedType (fullMessageName string ) bool {
113+ parent := fullMessageName [:strings .LastIndexByte (fullMessageName , '.' )]
114+ return b .messageTypes [parent ] != nil
115+ }
116+
117+ func buildIndent (level int ) string {
118+ return strings .Repeat (" " , level )
119+ }
0 commit comments