Skip to content

Commit

Permalink
Merge pull request #354 from appwrite/feat-preps-for-0.13
Browse files Browse the repository at this point in the history
Feat preps for 0.13
  • Loading branch information
TorstenDittmann authored Mar 2, 2022
2 parents 7ff9d42 + 0860d99 commit 0b49ac1
Show file tree
Hide file tree
Showing 170 changed files with 4,330 additions and 1,870 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/tests/sdks
/.vscode
.vs
.phpunit.*
.env
.envrc
.hatch
Expand Down
75 changes: 60 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,80 @@ The test algorithm will generate your SDK from a small demo SDK JSON spec file a

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

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

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`.

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

1. tests/languages/tests-for-php.js
2. tests/languages/tests-for-node.js
1. tests/languages/php/test.php
2. tests/languages/node/test.js

> 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.
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.
Once done, create a new test file `tests/[Language]Test.php` and update as the following.

A good example is the PHP test for 5 different PHP versions:
```php
<?php

namespace Tests;

class [Language]Test extends Base
{
protected string $language = '[language]';
protected string $class = 'Appwrite\SDK\Language\[Language]';
protected array $build = [
//commands required before executing the test
];
protected array $envs = [
// docker commands that can execute test file to the sdk test. Make sure to add
// one command for each lanuage version you wish to support
];

// list of expected outputs from test based on features supported
protected array $expectedOutput = [
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
...Base::EXCEPTION_RESPONSES,
...Base::REALTIME_RESPONSES
];
}
```

A good example is the Dart test:

```php
protected $containers = [
'php-5.6' => 'docker run --rm -v $(pwd):/app -w /app php:5.6-cli php tests/languages/tests-for-php.php',
'php-7.0' => 'docker run --rm -v $(pwd):/app -w /app php:7.0-cli php tests/languages/tests-for-php.php',
'php-7.1' => 'docker run --rm -v $(pwd):/app -w /app php:7.1-cli php tests/languages/tests-for-php.php',
'php-7.2' => 'docker run --rm -v $(pwd):/app -w /app php:7.2-cli php tests/languages/tests-for-php.php',
'php-7.3' => 'docker run --rm -v $(pwd):/app -w /app php:7.3-cli php tests/languages/tests-for-php.php',
'php-7.4' => 'docker run --rm -v $(pwd):/app -w /app php:7.4-cli php tests/languages/tests-for-php.php',
];
<?php

namespace Tests;

class DartTest extends Base
{
protected string $language = 'dart';
protected string $class = 'Appwrite\SDK\Language\Dart';
protected array $build = [
'mkdir -p tests/sdks/dart/tests',
'cp tests/languages/dart/tests.dart tests/sdks/dart/tests/tests.dart',
];
protected array $envs = [
'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"',
'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"',
];
protected array $expectedOutput = [
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
...Base::EXCEPTION_RESPONSES,
];
}
```

Finally, you can run the tests using
Also in `.travis.yml` add new env `SDK=[Language]` so that travis will run test for this language as well.

Finally, you can run tests using
```sh
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"
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"
```

## SDK Generator Interface
Expand Down
46 changes: 23 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 48 additions & 35 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

include_once 'vendor/autoload.php';

use Appwrite\SDK\Language\CLI;
use Appwrite\Spec\Swagger2;
use Appwrite\SDK\SDK;
use Appwrite\SDK\Language\Web;
use Appwrite\SDK\Language\Node;
use Appwrite\SDK\Language\CLI;
use Appwrite\SDK\Language\PHP;
use Appwrite\SDK\Language\Python;
use Appwrite\SDK\Language\Ruby;
Expand Down Expand Up @@ -39,7 +39,7 @@ function getSSLPage($url) {
// $spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1'); // Enable only with Appwrite local server running on port 80
// $spec = getSSLPage('https://appwrite.io/v1/open-api-2.json?extensions=1&platform=console'); // Enable only with Appwrite local server running on port 80
// $spec = file_get_contents('https://appwrite.io/specs/swagger2?platform=client');
$spec = file_get_contents('./specs/swagger-appwrite-0.12.0.json');
$spec = file_get_contents('./specs/swagger2-latest-console.json');

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

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

// Web
// // Web
$sdk = new SDK(new Web(), new Swagger2($spec));

$sdk
Expand Down Expand Up @@ -144,6 +144,51 @@ function getSSLPage($url) {

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

// CLI
$language = new CLI();
$language->setNPMPackage('appwrite-cli');
$language->setExecutableName('appwrite');
$language->setLogo(json_encode("
_ _ _ ___ __ _____
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
|_| |_|
"));
$language->setLogoUnescaped("
_ _ _ ___ __ _____
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
//_\\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
|_| |_| ");

$sdk = new SDK($language, new Swagger2($spec));

$sdk
->setName('NAME')
->setVersion('0.0.19')
->setDescription('Repo description goes here')
->setShortDescription('Repo short description goes here')
->setURL('https://appwrite.io')
->setLogo('https://appwrite.io/v1/images/console.png')
->setLicense('BSD-3-Clause')
->setLicenseContent('test test test')
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
->setChangelog('**CHANGELOG**')
->setGitUserName('appwrite')
->setGitRepoName('sdk-for-cli')
->setTwitter('appwrite_io')
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
->setDefaultHeaders([
'X-Appwrite-Response-Format' => '0.12.0',
])
;

$sdk->generate(__DIR__ . '/examples/cli');

// Ruby
$sdk = new SDK(new Ruby(), new Swagger2($spec));

Expand Down Expand Up @@ -363,38 +408,6 @@ function getSSLPage($url) {

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

// CLI
$cli = new CLI();
$cli->setExecutableName('appwrite');
$cli->setLogo("
_ _ _ ___ __ _____
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
//_\\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
|_| |_|
");
$sdk = new SDK($cli, new Swagger2($spec));
$sdk
->setName('NAME')
->setDescription('Repo description goes here')
->setShortDescription('Repo short description goes here')
->setURL('https://example.com')
->setLogo('https://appwrite.io/v1/images/console.png')
->setLicenseContent('test test test')
->setWarning('**WORK IN PROGRESS - NOT READY FOR USAGE**')
->setChangelog('**CHANGELOG**')
->setVersion('0.0.1')
->setGitUserName('repoowner')
->setGitRepoName('reponame')
->setTwitter('appwrite_io')
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
// ->setDefaultHeaders([
// 'X-Appwrite-Response-Format' => '0.7.0',
// ])
;
$sdk->generate(__DIR__ . '/examples/CLI');

// Android

$sdk = new SDK(new Android(), new Swagger2($spec));
Expand Down
1 change: 1 addition & 0 deletions specs/swagger-appwrite-0.12.1-console.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions specs/swagger-appwrite-0.13.0.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions specs/swagger2-latest-console.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/SDK/Language/Android.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public function getFiles()
'template' => '/android/library/src/main/java/io/appwrite/models/RealtimeModels.kt.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/models/UploadProgress.kt',
'template' => '/android/library/src/main/java/io/appwrite/models/UploadProgress.kt.twig',
'minify' => false,
],
[
'scope' => 'default',
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/WebAuthComponent.kt',
Expand Down
Loading

0 comments on commit 0b49ac1

Please sign in to comment.