Skip to content

Commit 0b49ac1

Browse files
Merge pull request #354 from appwrite/feat-preps-for-0.13
Feat preps for 0.13
2 parents 7ff9d42 + 0860d99 commit 0b49ac1

File tree

170 files changed

+4330
-1870
lines changed

Some content is hidden

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

170 files changed

+4330
-1870
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/tests/sdks
55
/.vscode
66
.vs
7+
.phpunit.*
78
.env
89
.envrc
910
.hatch

CONTRIBUTING.md

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,35 +179,80 @@ The test algorithm will generate your SDK from a small demo SDK JSON spec file a
179179

180180
To get started, create a language file in this location:
181181

182-
`./tests/languages/tests-for-[MY-LANGUAGE].[MY-LANGUAGE-FILE-EXT]`
182+
`./tests/languages/<language>/test.[MY-LANGUAGE-FILE-EXT]`
183183

184184
In your new language file, init your SDK from a relative path which will be generated here: `./tests/sdks/` from this spec file: `./tests/resources/spec.json`.
185185

186186
After you finish initializing, make a series of HTTP calls using your new generated SDKs method just like in one of these examples:
187187

188-
1. tests/languages/tests-for-php.js
189-
2. tests/languages/tests-for-node.js
188+
1. tests/languages/php/test.php
189+
2. tests/languages/node/test.js
190190

191191
> Note: In your test files, make sure that you begin the test with the following string "\nTest Started\n". We use this string to filter output from the build tool you're using.
192192
193-
Once done, add a Docker command that can execute your test file to the SDK test algorithm `$containers` array in this location: `./tests/SDKTest.php:17`. Make sure to add one command for each language version you wish to support.
193+
Once done, create a new test file `tests/[Language]Test.php` and update as the following.
194194

195-
A good example is the PHP test for 5 different PHP versions:
195+
```php
196+
<?php
197+
198+
namespace Tests;
199+
200+
class [Language]Test extends Base
201+
{
202+
protected string $language = '[language]';
203+
protected string $class = 'Appwrite\SDK\Language\[Language]';
204+
protected array $build = [
205+
//commands required before executing the test
206+
];
207+
protected array $envs = [
208+
// docker commands that can execute test file to the sdk test. Make sure to add
209+
// one command for each lanuage version you wish to support
210+
];
211+
212+
// list of expected outputs from test based on features supported
213+
protected array $expectedOutput = [
214+
...Base::FOO_RESPONSES,
215+
...Base::BAR_RESPONSES,
216+
...Base::GENERAL_RESPONSES,
217+
...Base::EXCEPTION_RESPONSES,
218+
...Base::REALTIME_RESPONSES
219+
];
220+
}
221+
```
222+
223+
A good example is the Dart test:
196224

197225
```php
198-
protected $containers = [
199-
'php-5.6' => 'docker run --rm -v $(pwd):/app -w /app php:5.6-cli php tests/languages/tests-for-php.php',
200-
'php-7.0' => 'docker run --rm -v $(pwd):/app -w /app php:7.0-cli php tests/languages/tests-for-php.php',
201-
'php-7.1' => 'docker run --rm -v $(pwd):/app -w /app php:7.1-cli php tests/languages/tests-for-php.php',
202-
'php-7.2' => 'docker run --rm -v $(pwd):/app -w /app php:7.2-cli php tests/languages/tests-for-php.php',
203-
'php-7.3' => 'docker run --rm -v $(pwd):/app -w /app php:7.3-cli php tests/languages/tests-for-php.php',
204-
'php-7.4' => 'docker run --rm -v $(pwd):/app -w /app php:7.4-cli php tests/languages/tests-for-php.php',
205-
];
226+
<?php
227+
228+
namespace Tests;
229+
230+
class DartTest extends Base
231+
{
232+
protected string $language = 'dart';
233+
protected string $class = 'Appwrite\SDK\Language\Dart';
234+
protected array $build = [
235+
'mkdir -p tests/sdks/dart/tests',
236+
'cp tests/languages/dart/tests.dart tests/sdks/dart/tests/tests.dart',
237+
];
238+
protected array $envs = [
239+
'dart-stable' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:stable sh -c "dart pub get && dart pub run tests/tests.dart"',
240+
'dart-beta' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:beta sh -c "dart pub get && dart pub run tests/tests.dart"',
241+
];
242+
protected array $expectedOutput = [
243+
...Base::FOO_RESPONSES,
244+
...Base::BAR_RESPONSES,
245+
...Base::GENERAL_RESPONSES,
246+
...Base::EXCEPTION_RESPONSES,
247+
];
248+
}
206249
```
207250

208-
Finally, you can run the tests using
251+
Also in `.travis.yml` add new env `SDK=[Language]` so that travis will run test for this language as well.
252+
253+
Finally, you can run tests using
209254
```sh
210-
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:7.4-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit tests/SDKTest.php"
255+
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:7.4-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit"
211256
```
212257

213258
## SDK Generator Interface

composer.lock

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

example.php

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
include_once 'vendor/autoload.php';
44

5-
use Appwrite\SDK\Language\CLI;
65
use Appwrite\Spec\Swagger2;
76
use Appwrite\SDK\SDK;
87
use Appwrite\SDK\Language\Web;
98
use Appwrite\SDK\Language\Node;
9+
use Appwrite\SDK\Language\CLI;
1010
use Appwrite\SDK\Language\PHP;
1111
use Appwrite\SDK\Language\Python;
1212
use Appwrite\SDK\Language\Ruby;
@@ -39,7 +39,7 @@ function getSSLPage($url) {
3939
// $spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1'); // Enable only with Appwrite local server running on port 80
4040
// $spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1&platform=console'); // Enable only with Appwrite local server running on port 80
4141
// $spec = file_get_contents('https://appwrite.io/specs/swagger2?platform=client');
42-
$spec = file_get_contents('./specs/swagger-appwrite-0.12.0.json');
42+
$spec = file_get_contents('./specs/swagger2-latest-console.json');
4343

4444
if(empty($spec)) {
4545
throw new Exception('Failed to fetch spec from Appwrite server');
@@ -72,7 +72,7 @@ function getSSLPage($url) {
7272

7373
$sdk->generate(__DIR__ . '/examples/php');
7474

75-
// Web
75+
// // Web
7676
$sdk = new SDK(new Web(), new Swagger2($spec));
7777

7878
$sdk
@@ -144,6 +144,51 @@ function getSSLPage($url) {
144144

145145
$sdk->generate(__DIR__ . '/examples/node');
146146

147+
// CLI
148+
$language = new CLI();
149+
$language->setNPMPackage('appwrite-cli');
150+
$language->setExecutableName('appwrite');
151+
$language->setLogo(json_encode("
152+
_ _ _ ___ __ _____
153+
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
154+
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
155+
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
156+
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
157+
|_| |_|
158+
159+
"));
160+
$language->setLogoUnescaped("
161+
_ _ _ ___ __ _____
162+
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
163+
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
164+
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
165+
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
166+
|_| |_| ");
167+
168+
$sdk = new SDK($language, new Swagger2($spec));
169+
170+
$sdk
171+
->setName('NAME')
172+
->setVersion('0.0.19')
173+
->setDescription('Repo description goes here')
174+
->setShortDescription('Repo short description goes here')
175+
->setURL('https://appwrite.io')
176+
->setLogo('https://appwrite.io/v1/images/console.png')
177+
->setLicense('BSD-3-Clause')
178+
->setLicenseContent('test test test')
179+
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
180+
->setChangelog('**CHANGELOG**')
181+
->setGitUserName('appwrite')
182+
->setGitRepoName('sdk-for-cli')
183+
->setTwitter('appwrite_io')
184+
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
185+
->setDefaultHeaders([
186+
'X-Appwrite-Response-Format' => '0.12.0',
187+
])
188+
;
189+
190+
$sdk->generate(__DIR__ . '/examples/cli');
191+
147192
// Ruby
148193
$sdk = new SDK(new Ruby(), new Swagger2($spec));
149194

@@ -363,38 +408,6 @@ function getSSLPage($url) {
363408

364409
$sdk->generate(__DIR__ . '/examples/HTTP');
365410

366-
// CLI
367-
$cli = new CLI();
368-
$cli->setExecutableName('appwrite');
369-
$cli->setLogo("
370-
_ _ _ ___ __ _____
371-
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
372-
//_\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
373-
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
374-
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
375-
|_| |_|
376-
");
377-
$sdk = new SDK($cli, new Swagger2($spec));
378-
$sdk
379-
->setName('NAME')
380-
->setDescription('Repo description goes here')
381-
->setShortDescription('Repo short description goes here')
382-
->setURL('https://example.com')
383-
->setLogo('https://appwrite.io/v1/images/console.png')
384-
->setLicenseContent('test test test')
385-
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
386-
->setChangelog('**CHANGELOG**')
387-
->setVersion('0.0.1')
388-
->setGitUserName('repoowner')
389-
->setGitRepoName('reponame')
390-
->setTwitter('appwrite_io')
391-
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
392-
// ->setDefaultHeaders([
393-
// 'X-Appwrite-Response-Format' => '0.7.0',
394-
// ])
395-
;
396-
$sdk->generate(__DIR__ . '/examples/CLI');
397-
398411
// Android
399412

400413
$sdk = new SDK(new Android(), new Swagger2($spec));

specs/swagger-appwrite-0.12.1-console.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

specs/swagger-appwrite-0.13.0.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

specs/swagger2-latest-console.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/SDK/Language/Android.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ public function getFiles()
158158
'template' => '/android/library/src/main/java/io/appwrite/models/RealtimeModels.kt.twig',
159159
'minify' => false,
160160
],
161+
[
162+
'scope' => 'default',
163+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/models/UploadProgress.kt',
164+
'template' => '/android/library/src/main/java/io/appwrite/models/UploadProgress.kt.twig',
165+
'minify' => false,
166+
],
161167
[
162168
'scope' => 'default',
163169
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/WebAuthComponent.kt',

0 commit comments

Comments
 (0)