@@ -82,6 +82,8 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
82
82
appender ( slice ) ;
83
83
else
84
84
append ( slice )
85
+
86
+ // TODO: structs need a proper recursive solution to fix omitempty and nesting
85
87
if ( sliceType == "struct" ) {
86
88
const allFields = { } ;
87
89
@@ -103,6 +105,28 @@ function jsonToGo(json, typename, flatten = true, example = false, allOmitempty
103
105
const currentValue = scope [ i ] [ keyname ] ;
104
106
105
107
if ( compareObjects ( existingValue , currentValue ) ) {
108
+ const currentKeys = Object . keys ( currentValue )
109
+ const existingKeys = Object . keys ( existingValue )
110
+
111
+ // try to merge two object fields instead of creating separate ones
112
+ if ( typeof existingValue === "object"
113
+ && existingKeys . length > 0
114
+ && typeof currentValue === "object"
115
+ && currentKeys . length > 0
116
+ ) {
117
+ var mergedValues = existingValue
118
+ for ( const key of currentKeys ) {
119
+ if ( ! Object . keys ( mergedValues ) . includes ( key ) ) {
120
+ mergedValues [ key ] = currentValue [ key ]
121
+ // TODO: find a proper handling of omitempty for nested structs
122
+ allOmitempty = true
123
+ }
124
+ }
125
+ allFields [ keyname ] . value = mergedValues ;
126
+ allFields [ keyname ] . count ++ ;
127
+ continue ;
128
+ }
129
+
106
130
const comparisonResult = compareObjectKeys (
107
131
Object . keys ( currentValue ) ,
108
132
Object . keys ( existingValue )
0 commit comments