Skip to content

Commit 57d000d

Browse files
committed
Merge branch 'master' into 883-fix-enum-casings
2 parents 117dd20 + 954f3d6 commit 57d000d

24 files changed

+954
-682
lines changed

composer.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SDK/Language/Go.php

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

templates/cli/index.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { login, logout, whoami, migrate, register } = require("./lib/commands/gen
1616
const { init } = require("./lib/commands/init");
1717
const { pull } = require("./lib/commands/pull");
1818
const { run } = require("./lib/commands/run");
19-
const { push } = require("./lib/commands/push");
19+
const { push, deploy } = require("./lib/commands/push");
2020
{% else %}
2121
const { migrate } = require("./lib/commands/generic");
2222
{% endif %}
@@ -67,6 +67,7 @@ program
6767
.addCommand(init)
6868
.addCommand(pull)
6969
.addCommand(push)
70+
.addCommand(deploy)
7071
.addCommand(run)
7172
.addCommand(logout)
7273
{% endif %}

templates/cli/lib/client.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Client {
118118

119119
body = formData;
120120
} else {
121-
body = JSON.stringify(params);
121+
body = JSONbig.stringify(params);
122122
}
123123

124124
let response = undefined;
@@ -174,7 +174,7 @@ class Client {
174174
const text = await response.text();
175175
let json = undefined;
176176
try {
177-
json = JSON.parse(text);
177+
json = JSONbig.parse(text);
178178
} catch (error) {
179179
return text;
180180
}

0 commit comments

Comments
 (0)