Skip to content

Commit d9f6d71

Browse files
authored
Merge branch 'master' into improve-json-serialization
2 parents 953600d + e1ca749 commit d9f6d71

File tree

161 files changed

+5969
-1256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+5969
-1256
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ jobs:
2020
CLINode18,
2121
DartBeta,
2222
DartStable,
23-
Deno1193,
24-
Deno1303,
2523
DotNet60,
2624
DotNet80,
2725
DotNet90,

composer.lock

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

example.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Appwrite\SDK\Language\Ruby;
1414
use Appwrite\SDK\Language\Dart;
1515
use Appwrite\SDK\Language\Go;
16-
use Appwrite\SDK\Language\Deno;
1716
use Appwrite\SDK\Language\REST;
1817
use Appwrite\SDK\Language\Swift;
1918
use Appwrite\SDK\Language\Apple;
@@ -42,7 +41,7 @@ function getSSLPage($url) {
4241
$platform = 'console';
4342
// $platform = 'server';
4443

45-
$version = '1.7.x';
44+
$version = '1.8.x';
4645
$spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/{$version}/app/config/specs/swagger2-{$version}-{$platform}.json");
4746

4847
if(empty($spec)) {
@@ -101,30 +100,6 @@ function getSSLPage($url) {
101100

102101
$sdk->generate(__DIR__ . '/examples/web');
103102

104-
// Deno
105-
$sdk = new SDK(new Deno(), new Swagger2($spec));
106-
107-
$sdk
108-
->setName('NAME')
109-
->setDescription('Repo description goes here')
110-
->setShortDescription('Repo short description goes here')
111-
->setVersion('0.0.0')
112-
->setURL('https://example.com')
113-
->setLogo('https://appwrite.io/v1/images/console.png')
114-
->setLicenseContent('test test test')
115-
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
116-
->setChangelog('**CHANGELOG**')
117-
->setGitUserName('repoowner')
118-
->setGitRepoName('reponame')
119-
->setTwitter('appwrite_io')
120-
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
121-
->setDefaultHeaders([
122-
'X-Appwrite-Response-Format' => '1.6.0',
123-
])
124-
;
125-
126-
$sdk->generate(__DIR__ . '/examples/deno');
127-
128103
// Node
129104
$sdk = new SDK(new Node(), new Swagger2($spec));
130105

@@ -192,6 +167,7 @@ function getSSLPage($url) {
192167
->setExclude([
193168
'services' => [
194169
['name' => 'assistant'],
170+
['name' => 'avatars'],
195171
],
196172
])
197173
;

src/SDK/Language/Android.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public function getFiles(): array
2626
],
2727
[
2828
'scope' => 'method',
29-
'destination' => 'docs/examples/kotlin/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
29+
'destination' => 'docs/examples/kotlin/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
3030
'template' => '/android/docs/kotlin/example.md.twig',
3131
],
3232
[
3333
'scope' => 'method',
34-
'destination' => 'docs/examples/java/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
34+
'destination' => 'docs/examples/java/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
3535
'template' => '/android/docs/java/example.md.twig',
3636
],
3737
[

src/SDK/Language/Apple.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getFiles(): array
3737
],
3838
[
3939
'scope' => 'method',
40-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
40+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
4141
'template' => 'swift/docs/example.md.twig',
4242
],
4343
[

src/SDK/Language/CLI.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getFiles(): array
163163
],
164164
[
165165
'scope' => 'method',
166-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
166+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
167167
'template' => 'cli/docs/example.md.twig',
168168
],
169169
[
@@ -231,6 +231,11 @@ public function getFiles(): array
231231
'destination' => 'lib/type-generation/languages/dart.js',
232232
'template' => 'cli/lib/type-generation/languages/dart.js.twig',
233233
],
234+
[
235+
'scope' => 'default',
236+
'destination' => 'lib/type-generation/languages/csharp.js',
237+
'template' => 'cli/lib/type-generation/languages/csharp.js.twig',
238+
],
234239
[
235240
'scope' => 'default',
236241
'destination' => 'lib/questions.js',
@@ -313,7 +318,7 @@ public function getFiles(): array
313318
],
314319
[
315320
'scope' => 'service',
316-
'destination' => '/lib/commands/{{service.name | caseDash}}.js',
321+
'destination' => '/lib/commands/{{service.name | caseKebab}}.js',
317322
'template' => 'cli/lib/commands/command.js.twig',
318323
],
319324
[
@@ -330,6 +335,11 @@ public function getFiles(): array
330335
'scope' => 'default',
331336
'destination' => 'lib/commands/types.js',
332337
'template' => 'cli/lib/commands/types.js.twig',
338+
],
339+
[
340+
'scope' => 'default',
341+
'destination' => 'lib/commands/update.js',
342+
'template' => 'cli/lib/commands/update.js.twig',
333343
]
334344
];
335345
}
@@ -360,7 +370,7 @@ public function getTypeName(array $parameter, array $spec = []): string
360370
self::TYPE_OBJECT => 'object',
361371
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
362372
? $this->getTypeName($parameter['array']) . '[]'
363-
: 'string[]',
373+
: 'any[]',
364374
default => $parameter['type'],
365375
};
366376
}
@@ -429,14 +439,6 @@ public function getParamExample(array $param): string
429439
return $output;
430440
}
431441

432-
public function getFilters(): array
433-
{
434-
return array_merge(parent::getFilters(), [
435-
new TwigFilter('caseKebab', function ($value) {
436-
return strtolower(preg_replace('/(?<!^)([A-Z][a-z]|(?<=[a-z])[^a-z\s]|(?<=[A-Z])[0-9_])/', '-$1', $value));
437-
})
438-
]);
439-
}
440442
/**
441443
* Language specific filters.
442444
* @return array

src/SDK/Language/Dart.php

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -226,49 +226,29 @@ public function getParamExample(array $param): string
226226
$type = $param['type'] ?? '';
227227
$example = $param['example'] ?? '';
228228

229-
$output = '';
229+
$hasExample = !empty($example) || $example === 0 || $example === false;
230230

231-
if (empty($example) && $example !== 0 && $example !== false) {
232-
switch ($type) {
233-
case self::TYPE_FILE:
234-
$output .= 'InputFile(path: \'./path-to-files/image.jpg\', filename: \'image.jpg\')';
235-
break;
236-
case self::TYPE_NUMBER:
237-
case self::TYPE_INTEGER:
238-
$output .= '0';
239-
break;
240-
case self::TYPE_BOOLEAN:
241-
$output .= 'false';
242-
break;
243-
case self::TYPE_STRING:
244-
$output .= "''";
245-
break;
246-
case self::TYPE_OBJECT:
247-
$output .= '{}';
248-
break;
249-
case self::TYPE_ARRAY:
250-
$output .= '[]';
251-
break;
252-
}
253-
} else {
254-
switch ($type) {
255-
case self::TYPE_OBJECT:
256-
case self::TYPE_FILE:
257-
case self::TYPE_NUMBER:
258-
case self::TYPE_INTEGER:
259-
case self::TYPE_ARRAY:
260-
$output .= $example;
261-
break;
262-
case self::TYPE_BOOLEAN:
263-
$output .= ($example) ? 'true' : 'false';
264-
break;
265-
case self::TYPE_STRING:
266-
$output .= "'{$example}'";
267-
break;
268-
}
231+
if (!$hasExample) {
232+
return match ($type) {
233+
self::TYPE_OBJECT => '{}',
234+
self::TYPE_ARRAY => '[]',
235+
self::TYPE_BOOLEAN => 'false',
236+
self::TYPE_FILE => 'InputFile(path: \'./path-to-files/image.jpg\', filename: \'image.jpg\')',
237+
self::TYPE_INTEGER, self::TYPE_NUMBER => '0',
238+
self::TYPE_STRING => "''",
239+
};
269240
}
270241

271-
return $output;
242+
return match ($type) {
243+
self::TYPE_ARRAY, self::TYPE_FILE, self::TYPE_INTEGER, self::TYPE_NUMBER => $example,
244+
self::TYPE_BOOLEAN => ($example) ? 'true' : 'false',
245+
self::TYPE_OBJECT => ($decoded = json_decode($example, true)) !== null
246+
? (empty($decoded) && $example === '{}'
247+
? '{}'
248+
: preg_replace('/\n/', "\n ", json_encode($decoded, JSON_PRETTY_PRINT)))
249+
: $example,
250+
self::TYPE_STRING => "'{$example}'",
251+
};
272252
}
273253

274254
/**
@@ -372,6 +352,11 @@ public function getFiles(): array
372352
'destination' => '/pubspec.yaml',
373353
'template' => 'dart/pubspec.yaml.twig',
374354
],
355+
[
356+
'scope' => 'default',
357+
'destination' => '/analysis_options.yaml',
358+
'template' => 'dart/analysis_options.yaml.twig',
359+
],
375360
[
376361
'scope' => 'default',
377362
'destination' => '/lib/client_io.dart',
@@ -409,7 +394,7 @@ public function getFiles(): array
409394
],
410395
[
411396
'scope' => 'service',
412-
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
397+
'destination' => '/lib/services/{{service.name | caseSnake}}.dart',
413398
'template' => 'dart/lib/services/service.dart.twig',
414399
],
415400
[
@@ -419,12 +404,12 @@ public function getFiles(): array
419404
],
420405
[
421406
'scope' => 'method',
422-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
407+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
423408
'template' => 'dart/docs/example.md.twig',
424409
],
425410
[
426411
'scope' => 'service',
427-
'destination' => '/test/services/{{service.name | caseDash}}_test.dart',
412+
'destination' => '/test/services/{{service.name | caseSnake}}_test.dart',
428413
'template' => 'dart/test/services/service_test.dart.twig',
429414
],
430415
[
@@ -487,6 +472,11 @@ public function getFiles(): array
487472
'destination' => '.github/workflows/format.yml',
488473
'template' => 'dart/.github/workflows/format.yml.twig',
489474
],
475+
[
476+
'scope' => 'default',
477+
'destination' => '.github/workflows/test.yml',
478+
'template' => 'dart/.github/workflows/test.yml',
479+
],
490480
[
491481
'scope' => 'default',
492482
'destination' => 'lib/src/input_file.dart',
@@ -506,7 +496,7 @@ public function getFilters(): array
506496
new TwigFilter('dartComment', function ($value) {
507497
$value = explode("\n", $value);
508498
foreach ($value as $key => $line) {
509-
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
499+
$value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// ");
510500
}
511501
return implode("\n", $value);
512502
}, ['is_safe' => ['html']]),

src/SDK/Language/Deno.php

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Appwrite\SDK\Language;
44

5-
use Twig\TwigFilter;
6-
75
class Deno extends JS
86
{
97
/**
@@ -92,12 +90,12 @@ public function getFiles(): array
9290
],
9391
[
9492
'scope' => 'service',
95-
'destination' => '/src/services/{{service.name | caseDash}}.ts',
93+
'destination' => '/src/services/{{service.name | caseKebab}}.ts',
9694
'template' => 'deno/src/services/service.ts.twig',
9795
],
9896
[
9997
'scope' => 'service',
100-
'destination' => '/test/services/{{service.name | caseDash}}.test.ts',
98+
'destination' => '/test/services/{{service.name | caseKebab}}.test.ts',
10199
'template' => 'deno/test/services/service.test.ts.twig',
102100
],
103101
[
@@ -117,12 +115,12 @@ public function getFiles(): array
117115
],
118116
[
119117
'scope' => 'method',
120-
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
118+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseKebab}}.md',
121119
'template' => 'deno/docs/example.md.twig',
122120
],
123121
[
124122
'scope' => 'enum',
125-
'destination' => 'src/enums/{{ enum.name | caseDash }}.ts',
123+
'destination' => 'src/enums/{{ enum.name | caseKebab }}.ts',
126124
'template' => 'deno/src/enums/enum.ts.twig',
127125
],
128126
];
@@ -150,7 +148,7 @@ public function getTypeName(array $parameter, array $spec = []): string
150148
self::TYPE_BOOLEAN => 'boolean',
151149
self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type']))
152150
? $this->getTypeName($parameter['array']) . '[]'
153-
: 'string[]',
151+
: 'any[]',
154152
self::TYPE_OBJECT => 'object',
155153
default => $parameter['type']
156154
};
@@ -165,48 +163,28 @@ public function getParamExample(array $param): string
165163
$type = $param['type'] ?? '';
166164
$example = $param['example'] ?? '';
167165

168-
$output = '';
166+
$hasExample = !empty($example) || $example === 0 || $example === false;
169167

170-
if (empty($example) && $example !== 0 && $example !== false) {
171-
switch ($type) {
172-
case self::TYPE_NUMBER:
173-
case self::TYPE_INTEGER:
174-
case self::TYPE_BOOLEAN:
175-
$output .= 'null';
176-
break;
177-
case self::TYPE_STRING:
178-
$output .= "''";
179-
break;
180-
case self::TYPE_ARRAY:
181-
$output .= '[]';
182-
break;
183-
case self::TYPE_OBJECT:
184-
$output .= '{}';
185-
break;
186-
case self::TYPE_FILE:
187-
$output .= "InputFile.fromPath('/path/to/file.png', 'file.png')";
188-
break;
189-
}
190-
} else {
191-
switch ($type) {
192-
case self::TYPE_NUMBER:
193-
case self::TYPE_INTEGER:
194-
case self::TYPE_ARRAY:
195-
case self::TYPE_OBJECT:
196-
$output .= $example;
197-
break;
198-
case self::TYPE_BOOLEAN:
199-
$output .= ($example) ? 'true' : 'false';
200-
break;
201-
case self::TYPE_STRING:
202-
$output .= "'{$example}'";
203-
break;
204-
case self::TYPE_FILE:
205-
$output .= "InputFile.fromPath('/path/to/file.png', 'file.png')";
206-
break;
207-
}
168+
if (!$hasExample) {
169+
return match ($type) {
170+
self::TYPE_ARRAY => '[]',
171+
self::TYPE_FILE => 'InputFile.fromPath(\'/path/to/file.png\', \'file.png\')',
172+
self::TYPE_INTEGER, self::TYPE_NUMBER, self::TYPE_BOOLEAN => 'null',
173+
self::TYPE_OBJECT => '{}',
174+
self::TYPE_STRING => "''",
175+
};
208176
}
209177

210-
return $output;
178+
return match ($type) {
179+
self::TYPE_ARRAY, self::TYPE_INTEGER, self::TYPE_NUMBER => $example,
180+
self::TYPE_FILE => 'InputFile.fromPath(\'/path/to/file.png\', \'file.png\')',
181+
self::TYPE_BOOLEAN => ($example) ? 'true' : 'false',
182+
self::TYPE_OBJECT => ($example === '{}')
183+
? '{}'
184+
: (($formatted = json_encode(json_decode($example, true), JSON_PRETTY_PRINT))
185+
? preg_replace('/\n/', "\n ", $formatted)
186+
: $example),
187+
self::TYPE_STRING => "'{$example}'",
188+
};
211189
}
212190
}

0 commit comments

Comments
 (0)