@@ -63,11 +63,6 @@ public function getFiles(): array
6363 'destination ' => 'go.mod ' ,
6464 'template ' => 'go/go.mod.twig ' ,
6565 ],
66- [
67- 'scope ' => 'default ' ,
68- 'destination ' => 'example/main.go ' ,
69- 'template ' => 'go/main.go.twig ' ,
70- ],
7166 [
7267 'scope ' => 'default ' ,
7368 'destination ' => 'README.md ' ,
@@ -83,6 +78,11 @@ public function getFiles(): array
8378 'destination ' => 'LICENSE ' ,
8479 'template ' => 'go/LICENSE.twig ' ,
8580 ],
81+ [
82+ 'scope ' => 'default ' ,
83+ 'destination ' => 'appwrite/appwrite.go ' ,
84+ 'template ' => 'go/appwrite.go.twig ' ,
85+ ],
8686 [
8787 'scope ' => 'default ' ,
8888 'destination ' => 'client/client.go ' ,
@@ -145,7 +145,9 @@ public function getTypeName(array $parameter, array $spec = []): string
145145 self ::TYPE_STRING => 'string ' ,
146146 self ::TYPE_BOOLEAN => 'bool ' ,
147147 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 ' ,
149151 default => $ parameter ['type ' ],
150152 };
151153 }
@@ -170,8 +172,10 @@ public function getParamDefault(array $param): string
170172 switch ($ type ) {
171173 case self ::TYPE_NUMBER :
172174 case self ::TYPE_INTEGER :
175+ $ output .= "0 " ;
176+ break ;
173177 case self ::TYPE_BOOLEAN :
174- $ output .= 'null ' ;
178+ $ output .= 'false ' ;
175179 break ;
176180 case self ::TYPE_STRING :
177181 $ output .= '"" ' ;
@@ -283,25 +287,34 @@ public function getFilters(): array
283287 }
284288 return implode ("\n" . $ indent , $ value );
285289 }, ['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{} ' ) {
287291 return $ this ->getPropertyType ($ property , $ spec , $ generic );
288292 }),
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{} ' ) {
290294 return $ this ->getReturnType ($ method , $ spec , $ namespace , $ generic );
291295 }),
292296 new TwigFilter ('caseEnumKey ' , function (string $ value ) {
293297 return $ this ->toUpperSnakeCase ($ value );
294- })
298+ }),
295299 ];
296300 }
297301
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
299303 {
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+
301314 return $ type ;
302315 }
303316
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
305318 {
306319 if ($ method ['type ' ] === 'webAuth ' ) {
307320 return 'bool ' ;
@@ -322,4 +335,27 @@ protected function getReturnType(array $method, array $spec, string $namespace,
322335
323336 return 'models. ' . $ ret ;
324337 }
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+ }
325361}
0 commit comments