@@ -141,7 +141,7 @@ public class ModelGenerator {
141
141
142
142
// If the type is an object, generate a new model and also create appropriate initalizers, declarations and decoders.
143
143
if subClassType == VariableType . kObjectType {
144
- let subClassName = generateModelForClass ( jsonValue. arrayValue [ 0 ] , className: variableName, isSubModule: true )
144
+ let subClassName = generateModelForClass ( mergeArrayToSingleObject ( jsonValue. arrayValue) , className: variableName, isSubModule: true )
145
145
declarations = declarations. stringByAppendingFormat ( variableDeclarationBuilder ( variableName, type: " [ \( subClassName) ] " ) )
146
146
initalizers = initalizers. stringByAppendingFormat ( " %@ \n " , initalizerForObjectArray ( variableName, className: subClassName, key: stringConstantName) )
147
147
decoders = decoders. stringByAppendingFormat ( " %@ \n " , decoderForVariable ( variableName, key: stringConstantName, type: " [ \( subClassName) ] " ) )
@@ -219,9 +219,10 @@ public class ModelGenerator {
219
219
220
220
// If the type is an object then make it the base class and generate stuff.
221
221
if subClassType == VariableType . kObjectType {
222
- self . generateModelForClass ( object [ 0 ] , className: className, isSubModule: false )
222
+ return self . generateModelForClass ( mergeArrayToSingleObject ( object) , className: className, isSubModule: false )
223
+ } else {
224
+ return " "
223
225
}
224
- return " "
225
226
}
226
227
227
228
return className
@@ -322,10 +323,10 @@ public class ModelGenerator {
322
323
323
324
if let _ = js. string {
324
325
type = VariableType . kStringType
325
- } else if let _ = js. number {
326
- type = VariableType . kNumberType
327
326
} else if let _ = js. bool {
328
327
type = VariableType . kBoolType
328
+ } else if let _ = js. number {
329
+ type = VariableType . kNumberType
329
330
} else if let _ = js. array {
330
331
type = VariableType . kArrayType
331
332
}
@@ -548,7 +549,7 @@ public class ModelGenerator {
548
549
*/
549
550
internal func replaceInternalKeywordsForVariableName( currentName: String ) -> String {
550
551
551
- let currentReservedName = [ " id " : " internalIdentifier " , " description " : " descriptionValue " , " _id " : " internalIdentifier " ]
552
+ let currentReservedName = [ " id " : " internalIdentifier " , " description " : " descriptionValue " , " _id " : " internalIdentifier " , " class " : " classProperty " , " struct " : " structProperty " , " internal " : " internalProperty " ]
552
553
for (key, value) in currentReservedName {
553
554
if key == currentName {
554
555
return value
@@ -557,5 +558,21 @@ public class ModelGenerator {
557
558
return currentName
558
559
559
560
}
561
+
562
+ internal func mergeArrayToSingleObject( items: [ JSON ] ) -> JSON {
563
+ var finalObject : JSON = JSON ( [ : ] )
564
+ for item in items {
565
+ for (key, jsonValue) in item {
566
+ if finalObject [ key] == nil {
567
+ finalObject [ key] = jsonValue
568
+ } else if let newValue = jsonValue. dictionary {
569
+ finalObject [ key] = mergeArrayToSingleObject ( [ JSON ( newValue) , finalObject [ key] ] )
570
+ } else if let newValue = jsonValue. array {
571
+ finalObject [ key] = mergeArrayToSingleObject ( newValue + finalObject[ key] . arrayValue)
572
+ }
573
+ }
574
+ }
575
+ return finalObject
576
+ }
560
577
561
578
}
0 commit comments