@@ -150,7 +150,9 @@ public function getTypeName(array $parameter, array $spec = []): string
150
150
self ::TYPE_STRING => 'string ' ,
151
151
self ::TYPE_BOOLEAN => 'bool ' ,
152
152
self ::TYPE_OBJECT => 'interface{} ' ,
153
- self ::TYPE_ARRAY => '[]interface{} ' ,
153
+ self ::TYPE_ARRAY => (!empty (($ parameter ['array ' ] ?? [])['type ' ]) && !\is_array ($ parameter ['array ' ]['type ' ]))
154
+ ? '[] ' . $ this ->getTypeName ($ parameter ['array ' ])
155
+ : '[]string ' ,
154
156
default => $ parameter ['type ' ],
155
157
};
156
158
}
@@ -175,8 +177,10 @@ public function getParamDefault(array $param): string
175
177
switch ($ type ) {
176
178
case self ::TYPE_NUMBER :
177
179
case self ::TYPE_INTEGER :
180
+ $ output .= "0 " ;
181
+ break ;
178
182
case self ::TYPE_BOOLEAN :
179
- $ output .= 'null ' ;
183
+ $ output .= 'false ' ;
180
184
break ;
181
185
case self ::TYPE_STRING :
182
186
$ output .= '"" ' ;
@@ -288,25 +292,38 @@ public function getFilters(): array
288
292
}
289
293
return implode ("\n" . $ indent , $ value );
290
294
}, ['is_safe ' => ['html ' ]]),
291
- new TwigFilter ('propertyType ' , function (array $ property , array $ spec , string $ generic = 'interface{} ' ) {
295
+ new TwigFilter ('propertyType ' , function (array $ property , array $ spec , string $ generic = 'map[string] interface{} ' ) {
292
296
return $ this ->getPropertyType ($ property , $ spec , $ generic );
293
297
}),
294
- new TwigFilter ('returnType ' , function (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' ) {
298
+ new TwigFilter ('returnType ' , function (array $ method , array $ spec , string $ namespace , string $ generic = 'map[string]interface{} ' ) {
295
299
return $ this ->getReturnType ($ method , $ spec , $ namespace , $ generic );
296
300
}),
297
301
new TwigFilter ('caseEnumKey ' , function (string $ value ) {
298
302
return $ this ->toUpperSnakeCase ($ value );
299
- })
303
+ }),
300
304
];
301
305
}
302
306
303
- protected function getPropertyType (array $ property , array $ spec , string $ generic = 'interface{} ' ): string
307
+ protected function getPropertyType (array $ property , array $ spec , string $ generic = 'map[string] interface{} ' ): string
304
308
{
305
- $ type = $ this ->getTypeName ($ property );
309
+ if (\array_key_exists ('sub_schema ' , $ property )) {
310
+ $ type = $ this ->toPascalCase ($ property ['sub_schema ' ]);
311
+
312
+ if ($ this ->hasGenericType ($ property ['sub_schema ' ], $ spec )) {
313
+ $ type = $ generic ;
314
+ }
315
+
316
+ if ($ property ['type ' ] === 'array ' ) {
317
+ $ type = '[] ' . $ type ;
318
+ }
319
+ } else {
320
+ $ type = $ this ->getTypeName ($ property );
321
+ }
322
+
306
323
return $ type ;
307
324
}
308
325
309
- protected function getReturnType (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' ): string
326
+ protected function getReturnType (array $ method , array $ spec , string $ namespace , string $ generic = 'map[string]interface{} ' ): string
310
327
{
311
328
if ($ method ['type ' ] === 'webAuth ' ) {
312
329
return 'bool ' ;
@@ -327,4 +344,27 @@ protected function getReturnType(array $method, array $spec, string $namespace,
327
344
328
345
return 'models. ' . $ ret ;
329
346
}
347
+
348
+ protected function hasGenericType (?string $ model , array $ spec ): string
349
+ {
350
+ if (empty ($ model ) || $ model === 'any ' ) {
351
+ return false ;
352
+ }
353
+
354
+ $ model = $ spec ['definitions ' ][$ model ];
355
+
356
+ if ($ model ['additionalProperties ' ]) {
357
+ return true ;
358
+ }
359
+
360
+ foreach ($ model ['properties ' ] as $ property ) {
361
+ if (!\array_key_exists ('sub_schema ' , $ property ) || !$ property ['sub_schema ' ]) {
362
+ continue ;
363
+ }
364
+
365
+ return $ this ->hasGenericType ($ property ['sub_schema ' ], $ spec );
366
+ }
367
+
368
+ return false ;
369
+ }
330
370
}
0 commit comments