@@ -63,11 +63,6 @@ public function getFiles(): array
63
63
'destination ' => 'go.mod ' ,
64
64
'template ' => 'go/go.mod.twig ' ,
65
65
],
66
- [
67
- 'scope ' => 'default ' ,
68
- 'destination ' => 'example/main.go ' ,
69
- 'template ' => 'go/main.go.twig ' ,
70
- ],
71
66
[
72
67
'scope ' => 'default ' ,
73
68
'destination ' => 'README.md ' ,
@@ -83,6 +78,11 @@ public function getFiles(): array
83
78
'destination ' => 'LICENSE ' ,
84
79
'template ' => 'go/LICENSE.twig ' ,
85
80
],
81
+ [
82
+ 'scope ' => 'default ' ,
83
+ 'destination ' => 'appwrite/appwrite.go ' ,
84
+ 'template ' => 'go/appwrite.go.twig ' ,
85
+ ],
86
86
[
87
87
'scope ' => 'default ' ,
88
88
'destination ' => 'client/client.go ' ,
@@ -145,7 +145,9 @@ public function getTypeName(array $parameter, array $spec = []): string
145
145
self ::TYPE_STRING => 'string ' ,
146
146
self ::TYPE_BOOLEAN => 'bool ' ,
147
147
self ::TYPE_OBJECT => 'interface{} ' ,
148
- self ::TYPE_ARRAY => '[]interface{} ' ,
148
+ self ::TYPE_ARRAY => (!empty (($ parameter ['array ' ] ?? [])['type ' ]) && !\is_array ($ parameter ['array ' ]['type ' ]))
149
+ ? '[] ' . $ this ->getTypeName ($ parameter ['array ' ])
150
+ : '[]string ' ,
149
151
default => $ parameter ['type ' ],
150
152
};
151
153
}
@@ -170,8 +172,10 @@ public function getParamDefault(array $param): string
170
172
switch ($ type ) {
171
173
case self ::TYPE_NUMBER :
172
174
case self ::TYPE_INTEGER :
175
+ $ output .= "0 " ;
176
+ break ;
173
177
case self ::TYPE_BOOLEAN :
174
- $ output .= 'null ' ;
178
+ $ output .= 'false ' ;
175
179
break ;
176
180
case self ::TYPE_STRING :
177
181
$ output .= '"" ' ;
@@ -283,25 +287,34 @@ public function getFilters(): array
283
287
}
284
288
return implode ("\n" . $ indent , $ value );
285
289
}, ['is_safe ' => ['html ' ]]),
286
- new TwigFilter ('propertyType ' , function (array $ property , array $ spec , string $ generic = 'interface{} ' ) {
290
+ new TwigFilter ('propertyType ' , function (array $ property , array $ spec , string $ generic = 'map[string] interface{} ' ) {
287
291
return $ this ->getPropertyType ($ property , $ spec , $ generic );
288
292
}),
289
- new TwigFilter ('returnType ' , function (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' ) {
293
+ new TwigFilter ('returnType ' , function (array $ method , array $ spec , string $ namespace , string $ generic = 'map[string]interface{} ' ) {
290
294
return $ this ->getReturnType ($ method , $ spec , $ namespace , $ generic );
291
295
}),
292
296
new TwigFilter ('caseEnumKey ' , function (string $ value ) {
293
297
return $ this ->toUpperSnakeCase ($ value );
294
- })
298
+ }),
295
299
];
296
300
}
297
301
298
- protected function getPropertyType (array $ property , array $ spec , string $ generic = 'interface{} ' ): string
302
+ protected function getPropertyType (array $ property , array $ spec , string $ generic = 'map[string] interface{} ' ): string
299
303
{
300
- $ type = $ this ->getTypeName ($ property );
304
+ if (\array_key_exists ('sub_schema ' , $ property )) {
305
+ $ type = $ this ->toPascalCase ($ property ['sub_schema ' ]);
306
+
307
+ if ($ property ['type ' ] === 'array ' ) {
308
+ $ type = '[] ' . $ type ;
309
+ }
310
+ } else {
311
+ $ type = $ this ->getTypeName ($ property );
312
+ }
313
+
301
314
return $ type ;
302
315
}
303
316
304
- protected function getReturnType (array $ method , array $ spec , string $ namespace , string $ generic = 'T ' ): string
317
+ protected function getReturnType (array $ method , array $ spec , string $ namespace , string $ generic = 'map[string]interface{} ' ): string
305
318
{
306
319
if ($ method ['type ' ] === 'webAuth ' ) {
307
320
return 'bool ' ;
@@ -322,4 +335,27 @@ protected function getReturnType(array $method, array $spec, string $namespace,
322
335
323
336
return 'models. ' . $ ret ;
324
337
}
338
+
339
+ protected function hasGenericType (?string $ model , array $ spec ): string
340
+ {
341
+ if (empty ($ model ) || $ model === 'any ' ) {
342
+ return false ;
343
+ }
344
+
345
+ $ model = $ spec ['definitions ' ][$ model ];
346
+
347
+ if ($ model ['additionalProperties ' ]) {
348
+ return true ;
349
+ }
350
+
351
+ foreach ($ model ['properties ' ] as $ property ) {
352
+ if (!\array_key_exists ('sub_schema ' , $ property ) || !$ property ['sub_schema ' ]) {
353
+ continue ;
354
+ }
355
+
356
+ return $ this ->hasGenericType ($ property ['sub_schema ' ], $ spec );
357
+ }
358
+
359
+ return false ;
360
+ }
325
361
}
0 commit comments