@@ -46,6 +46,12 @@ func recursiveGetElementForStruct(p *pack.Package, structName string, obj *objec
4646 treeElement , cached := p .CachedElements [structName ]
4747 if cached {
4848 retTreeElement := objectToElement (obj , treeElement .GoType )
49+ if treeElement .Collection {
50+ retTreeElement .Collection = true
51+ }
52+ if treeElement .Map {
53+ retTreeElement .Map = true
54+ }
4955 retTreeElement .SubElements = treeElement .SubElements
5056 return retTreeElement , nil
5157 }
@@ -128,6 +134,8 @@ func getElementForStructInFile(path string, structName string, obj *object.Objec
128134 return false
129135 }
130136 if subElement != nil {
137+ element .Collection = subElement .Collection
138+ element .Map = subElement .Map
131139 if subElement .SubElements != nil {
132140 element .SubElements = append (element .SubElements , subElement .SubElements ... )
133141 }
@@ -155,6 +163,8 @@ func getElementForStructInFile(path string, structName string, obj *object.Objec
155163 }
156164 if subElement != nil {
157165 if subElement .SubElements != nil {
166+ element .Map = subElement .Map
167+ element .Collection = subElement .Collection
158168 element .SubElements = append (element .SubElements , subElement .SubElements ... )
159169 }
160170 }
@@ -169,7 +179,7 @@ func getElementForStructInFile(path string, structName string, obj *object.Objec
169179 identX := sel .X .(* ast.Ident )
170180
171181 fieldObj .Fieldname = structName
172- fieldObj .Collection = false
182+ fieldObj .Collection = true
173183
174184 importPath := modules .CachedModule (path ).GetPathForImport (imports [identX .Name ])
175185 fieldObj .PackageName = filepath .Base (importPath )
@@ -179,6 +189,8 @@ func getElementForStructInFile(path string, structName string, obj *object.Objec
179189 }
180190 if subElement != nil {
181191 if subElement .SubElements != nil {
192+ element .Map = subElement .Map
193+ element .Collection = subElement .Collection
182194 element .SubElements = append (element .SubElements , subElement .SubElements ... )
183195 }
184196 }
@@ -274,8 +286,14 @@ func getElementForStructInFile(path string, structName string, obj *object.Objec
274286 return false
275287 }
276288 if subElement != nil {
277- // another struct type
278- element .SubElements = append (element .SubElements , subElement )
289+ if subElement .Inline {
290+ if subElement .SubElements != nil {
291+ element .SubElements = append (element .SubElements , subElement .SubElements ... )
292+ }
293+ } else {
294+ // another struct type
295+ element .SubElements = append (element .SubElements , subElement )
296+ }
279297 } else {
280298 // basic types
281299 element .SubElements = append (element .SubElements , objectToElement (fieldObj , t ))
@@ -349,10 +367,27 @@ func getVariableFromField(src []byte, field *ast.Field) (varName string, impName
349367 copyParts = append (copyParts , part )
350368 }
351369 }
352- parts = copyParts
353370
354- varName = parts [0 ]
355- inlineType := parts [1 ]
371+ startTrim := false
372+ parts = make ([]string , 0 )
373+ for _ , part := range copyParts {
374+ if strings .HasPrefix (part , "`" ) {
375+ startTrim = true
376+ }
377+ if ! startTrim {
378+ parts = append (parts , part )
379+ }
380+ }
381+
382+ inlineType := ""
383+ if len (parts ) >= 2 {
384+ varName = parts [0 ]
385+ inlineType = parts [1 ]
386+ } else if len (parts ) < 2 {
387+ varName = ""
388+ inlineType = parts [0 ]
389+ }
390+
356391 if strings .HasPrefix (inlineType , "map" ) {
357392 inlineType = strings .TrimPrefix (inlineType , "map" )
358393 mp = true
@@ -378,5 +413,6 @@ func getVariableFromField(src []byte, field *ast.Field) (varName string, impName
378413 } else {
379414 typeName = typeParts [0 ]
380415 }
416+
381417 return
382418}
0 commit comments