From e76d30554f8979e18f4b106e876a47df59a7f30f Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 19 Jun 2023 17:54:46 +0530 Subject: [PATCH 01/98] feat: enum whitelist --- composer.lock | 160 +++++++++----------- src/SDK/Language/Dart.php | 10 ++ src/SDK/SDK.php | 22 +++ src/Spec/Swagger2.php | 1 + templates/dart/lib/enums.dart.twig | 5 + templates/dart/lib/src/enums/enum.dart.twig | 8 + 6 files changed, 119 insertions(+), 87 deletions(-) create mode 100644 templates/dart/lib/enums.dart.twig create mode 100644 templates/dart/lib/src/enums/enum.dart.twig diff --git a/composer.lock b/composer.lock index eb0e7c2a9..c9f53aca0 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "matthiasmullie/minify", - "version": "1.3.70", + "version": "1.3.71", "source": { "type": "git", "url": "https://github.com/matthiasmullie/minify.git", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b" + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/2807d9f9bece6877577ad44acb5c801bb3ae536b", - "reference": "2807d9f9bece6877577ad44acb5c801bb3ae536b", + "url": "https://api.github.com/repos/matthiasmullie/minify/zipball/ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", + "reference": "ae42a47d7fecc1fbb7277b2f2d84c37a33edc3b1", "shasum": "" }, "require": { @@ -67,7 +67,7 @@ ], "support": { "issues": "https://github.com/matthiasmullie/minify/issues", - "source": "https://github.com/matthiasmullie/minify/tree/1.3.70" + "source": "https://github.com/matthiasmullie/minify/tree/1.3.71" }, "funding": [ { @@ -75,7 +75,7 @@ "type": "github" } ], - "time": "2022-12-09T12:56:44+00:00" + "time": "2023-04-25T20:33:03+00:00" }, { "name": "matthiasmullie/path-converter", @@ -297,16 +297,16 @@ }, { "name": "twig/twig", - "version": "v3.5.1", + "version": "v3.6.1", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15" + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/a6e0510cc793912b451fd40ab983a1d28f611c15", - "reference": "a6e0510cc793912b451fd40ab983a1d28f611c15", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", + "reference": "7e7d5839d4bec168dfeef0ac66d5c5a2edbabffd", "shasum": "" }, "require": { @@ -315,15 +315,10 @@ "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { - "psr/container": "^1.0", + "psr/container": "^1.0|^2.0", "symfony/phpunit-bridge": "^4.4.9|^5.0.9|^6.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.5-dev" - } - }, "autoload": { "psr-4": { "Twig\\": "src/" @@ -357,7 +352,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.5.1" + "source": "https://github.com/twigphp/Twig/tree/v3.6.1" }, "funding": [ { @@ -369,22 +364,22 @@ "type": "tidelift" } ], - "time": "2023-02-08T07:49:20+00:00" + "time": "2023-06-08T12:52:13+00:00" } ], "packages-dev": [ { "name": "brianium/paratest", - "version": "v6.9.1", + "version": "v6.10.0", "source": { "type": "git", "url": "https://github.com/paratestphp/paratest.git", - "reference": "51691208db882922c55d6c465be3e7d95028c449" + "reference": "c2243b20bcd99c3f651018d1447144372f39b4fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paratestphp/paratest/zipball/51691208db882922c55d6c465be3e7d95028c449", - "reference": "51691208db882922c55d6c465be3e7d95028c449", + "url": "https://api.github.com/repos/paratestphp/paratest/zipball/c2243b20bcd99c3f651018d1447144372f39b4fa", + "reference": "c2243b20bcd99c3f651018d1447144372f39b4fa", "shasum": "" }, "require": { @@ -451,7 +446,7 @@ ], "support": { "issues": "https://github.com/paratestphp/paratest/issues", - "source": "https://github.com/paratestphp/paratest/tree/v6.9.1" + "source": "https://github.com/paratestphp/paratest/tree/v6.10.0" }, "funding": [ { @@ -463,7 +458,7 @@ "type": "paypal" } ], - "time": "2023-03-03T09:35:17+00:00" + "time": "2023-05-25T13:47:58+00:00" }, { "name": "doctrine/instantiator", @@ -716,16 +711,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.4", + "version": "v4.15.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290" + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290", - "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", "shasum": "" }, "require": { @@ -766,9 +761,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5" }, - "time": "2023-03-05T19:49:14+00:00" + "time": "2023-05-19T20:20:00+00:00" }, { "name": "phar-io/manifest", @@ -1201,16 +1196,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.6", + "version": "9.6.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115" + "reference": "a9aceaf20a682aeacf28d582654a1670d8826778" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b65d59a059d3004a040c16a82e07bbdf6cfdd115", - "reference": "b65d59a059d3004a040c16a82e07bbdf6cfdd115", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a9aceaf20a682aeacf28d582654a1670d8826778", + "reference": "a9aceaf20a682aeacf28d582654a1670d8826778", "shasum": "" }, "require": { @@ -1284,7 +1279,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.6" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.9" }, "funding": [ { @@ -1300,7 +1295,7 @@ "type": "tidelift" } ], - "time": "2023-03-27T11:43:46+00:00" + "time": "2023-06-11T06:13:56+00:00" }, { "name": "psr/container", @@ -1655,16 +1650,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.4", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3461e3fccc7cfdfc2720be910d3bd73c69be590d", - "reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -1709,7 +1704,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -1717,7 +1712,7 @@ "type": "github" } ], - "time": "2020-10-26T13:10:38+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "sebastian/environment", @@ -2378,23 +2373,23 @@ }, { "name": "symfony/console", - "version": "v6.2.8", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "3582d68a64a86ec25240aaa521ec8bc2342b369b" + "reference": "8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/3582d68a64a86ec25240aaa521ec8bc2342b369b", - "reference": "3582d68a64a86ec25240aaa521ec8bc2342b369b", + "url": "https://api.github.com/repos/symfony/console/zipball/8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7", + "reference": "8788808b07cf0bdd6e4b7fdd23d8ddb1470c83b7", "shasum": "" }, "require": { "php": ">=8.1", - "symfony/deprecation-contracts": "^2.1|^3", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", - "symfony/service-contracts": "^1.1|^2|^3", + "symfony/service-contracts": "^2.5|^3", "symfony/string": "^5.4|^6.0" }, "conflict": { @@ -2416,12 +2411,6 @@ "symfony/process": "^5.4|^6.0", "symfony/var-dumper": "^5.4|^6.0" }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/lock": "", - "symfony/process": "" - }, "type": "library", "autoload": { "psr-4": { @@ -2454,7 +2443,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.2.8" + "source": "https://github.com/symfony/console/tree/v6.3.0" }, "funding": [ { @@ -2470,20 +2459,20 @@ "type": "tidelift" } ], - "time": "2023-03-29T21:42:15+00:00" + "time": "2023-05-29T12:49:39+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v3.2.1", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e" + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", "shasum": "" }, "require": { @@ -2492,7 +2481,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.3-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -2521,7 +2510,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" }, "funding": [ { @@ -2537,7 +2526,7 @@ "type": "tidelift" } ], - "time": "2023-03-01T10:25:55+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -2706,16 +2695,16 @@ }, { "name": "symfony/process", - "version": "v6.2.8", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "75ed64103df4f6615e15a7fe38b8111099f47416" + "reference": "8741e3ed7fe2e91ec099e02446fb86667a0f1628" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/75ed64103df4f6615e15a7fe38b8111099f47416", - "reference": "75ed64103df4f6615e15a7fe38b8111099f47416", + "url": "https://api.github.com/repos/symfony/process/zipball/8741e3ed7fe2e91ec099e02446fb86667a0f1628", + "reference": "8741e3ed7fe2e91ec099e02446fb86667a0f1628", "shasum": "" }, "require": { @@ -2747,7 +2736,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v6.2.8" + "source": "https://github.com/symfony/process/tree/v6.3.0" }, "funding": [ { @@ -2763,20 +2752,20 @@ "type": "tidelift" } ], - "time": "2023-03-09T16:20:02+00:00" + "time": "2023-05-19T08:06:44+00:00" }, { "name": "symfony/service-contracts", - "version": "v3.2.1", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "a8c9cedf55f314f3a186041d19537303766df09a" + "reference": "40da9cc13ec349d9e4966ce18b5fbcd724ab10a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/a8c9cedf55f314f3a186041d19537303766df09a", - "reference": "a8c9cedf55f314f3a186041d19537303766df09a", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/40da9cc13ec349d9e4966ce18b5fbcd724ab10a4", + "reference": "40da9cc13ec349d9e4966ce18b5fbcd724ab10a4", "shasum": "" }, "require": { @@ -2786,13 +2775,10 @@ "conflict": { "ext-psr": "<1.1|>=2" }, - "suggest": { - "symfony/service-implementation": "" - }, "type": "library", "extra": { "branch-alias": { - "dev-main": "3.3-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -2832,7 +2818,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.2.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.3.0" }, "funding": [ { @@ -2848,20 +2834,20 @@ "type": "tidelift" } ], - "time": "2023-03-01T10:32:47+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "symfony/string", - "version": "v6.2.8", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "193e83bbd6617d6b2151c37fff10fa7168ebddef" + "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/193e83bbd6617d6b2151c37fff10fa7168ebddef", - "reference": "193e83bbd6617d6b2151c37fff10fa7168ebddef", + "url": "https://api.github.com/repos/symfony/string/zipball/f2e190ee75ff0f5eced645ec0be5c66fac81f51f", + "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f", "shasum": "" }, "require": { @@ -2872,13 +2858,13 @@ "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/translation-contracts": "<2.0" + "symfony/translation-contracts": "<2.5" }, "require-dev": { "symfony/error-handler": "^5.4|^6.0", "symfony/http-client": "^5.4|^6.0", "symfony/intl": "^6.2", - "symfony/translation-contracts": "^2.0|^3.0", + "symfony/translation-contracts": "^2.5|^3.0", "symfony/var-exporter": "^5.4|^6.0" }, "type": "library", @@ -2918,7 +2904,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.2.8" + "source": "https://github.com/symfony/string/tree/v6.3.0" }, "funding": [ { @@ -2934,7 +2920,7 @@ "type": "tidelift" } ], - "time": "2023-03-20T16:06:02+00:00" + "time": "2023-03-21T21:06:29+00:00" }, { "name": "theseer/tokenizer", diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 16c704092..d1366e877 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -411,6 +411,16 @@ public function getFiles(): array 'destination' => 'lib/src/input_file.dart', 'template' => 'dart/lib/src/input_file.dart.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart', + 'template' => 'dart/lib/src/enums/enum.dart.twig', + ], + [ + 'scope' => 'default', + 'destination' => 'lib/enums.dart', + 'template' => 'dart/lib/enums.dart.twig', + ], ]; } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 73a75ce39..e2badec6f 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -634,6 +634,28 @@ public function generate(string $target): void } } break; + case 'enum': + foreach ($this->spec->getServices() as $key => $service) { + $methods = $this->spec->getMethods($key); + + + foreach ($methods as $method) { + $params['method'] = $method; + $parameters = $method['parameters']['path']; + + foreach ($parameters as $parameter) { + // Check if the enum field is defined + if ($parameter['enum'] != null) { + $params['enum'] = [ + 'name' => $parameter['name'], + 'enum' => $parameter['enum'], + ]; + $this->render($template, $destination, $block, $params, $minify); + } + } + } + } + break; } } } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 202e7dc43..d19cefc90 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -227,6 +227,7 @@ public function getMethods($service) $output['parameters']['header'][] = $param; break; case 'path': + $param['enum'] = $parameter['enum'] ?? null; $output['parameters']['path'][] = $param; break; case 'query': diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig new file mode 100644 index 000000000..e075e3f0e --- /dev/null +++ b/templates/dart/lib/enums.dart.twig @@ -0,0 +1,5 @@ +library {{ language.params.packageName }}.enums; + +{% for enum in spec.enum %} +part 'src/enum/{{enum.name | caseSnake}}.dart'; +{% endfor %} \ No newline at end of file diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig new file mode 100644 index 000000000..40b3d51e1 --- /dev/null +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -0,0 +1,8 @@ +part of {{ language.params.packageName }}.enums; + +enum {{ enum.name | caseUcfirst | overrideIdentifier }} { + {% for value in enum.enum %} + {{value}}{% if not loop.last %}, +{% endif %} + {% endfor %} +} \ No newline at end of file From 11441b61438e22ba77cc82de15169d70bee4ab13 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 12 Jul 2023 13:06:11 +0530 Subject: [PATCH 02/98] (chore): fix common name renders --- src/SDK/Language.php | 21 +++++++++++++++++++++ src/SDK/SDK.php | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/SDK/Language.php b/src/SDK/Language.php index 0a7a259f7..2c47493d7 100644 --- a/src/SDK/Language.php +++ b/src/SDK/Language.php @@ -97,4 +97,25 @@ protected function toCamelCase($str): string $str = str_replace(" ", "", $str); return lcfirst($str); } + + public function getEnumType(string $service, string $method): string + { + switch ($service) { + case 'account': + switch ($method) { + case 'createOAuth2Session': + return 'Provider'; + } + case 'avatars': + switch ($method) { + case 'getBrowser': + return 'Browser'; + case 'getCreditCard': + return 'CreditCard'; + case 'getFlag': + return 'Flag'; + } + } + throw new \Exception('Enum type not found for service: ' . $service . ' method: ' . $method); + } } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index e2badec6f..ffbe165e4 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -140,6 +140,9 @@ public function __construct(Language $language, Spec $spec) $this->twig->addFilter(new TwigFilter('typeName', function ($value) { return $this->language->getTypeName($value); }, ['is_safe' => ['html']])); + $this->twig->addFilter(new TwigFilter('getEnumType', function ($service, $method) { + return $this->language->getEnumType($service, $method); + }, ['is_safe' => ['html']])); $this->twig->addFilter(new TwigFilter('paramDefault', function ($value) { return $this->language->getParamDefault($value); }, ['is_safe' => ['html']])); @@ -647,9 +650,9 @@ public function generate(string $target): void // Check if the enum field is defined if ($parameter['enum'] != null) { $params['enum'] = [ - 'name' => $parameter['name'], + 'name' => $this->language->getEnumType($service['name'], $method['name']), 'enum' => $parameter['enum'], - ]; + ]; $this->render($template, $destination, $block, $params, $minify); } } From 3aff6bf83214f388096c188ee5bf2c0b50460699 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 12 Jul 2023 17:11:17 +0530 Subject: [PATCH 03/98] chore: add support for node,web,php,web,flutter --- src/SDK/Language/Flutter.php | 10 ++++++++++ src/SDK/Language/Node.php | 5 +++++ src/SDK/Language/PHP.php | 5 +++++ src/SDK/Language/Python.php | 5 +++++ src/SDK/Language/Web.php | 5 +++++ templates/dart/lib/enums.dart.twig | 2 +- templates/node/lib/enums/enum.js.twig | 8 ++++++++ templates/php/src/Enums/Enum.php.twig | 9 +++++++++ templates/python/package/enums/enum.py.twig | 6 ++++++ templates/web/src/enums/enum.ts.twig | 5 +++++ 10 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 templates/node/lib/enums/enum.js.twig create mode 100644 templates/php/src/Enums/Enum.php.twig create mode 100644 templates/python/package/enums/enum.py.twig create mode 100644 templates/web/src/enums/enum.ts.twig diff --git a/src/SDK/Language/Flutter.php b/src/SDK/Language/Flutter.php index 1b5dea379..c9eebf412 100644 --- a/src/SDK/Language/Flutter.php +++ b/src/SDK/Language/Flutter.php @@ -250,6 +250,16 @@ public function getFiles(): array 'destination' => '.travis.yml', 'template' => 'flutter/.travis.yml.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart', + 'template' => 'dart/lib/src/enums/enum.dart.twig', + ], + [ + 'scope' => 'default', + 'destination' => 'lib/enums.dart', + 'template' => 'dart/lib/enums.dart.twig', + ], ]; } } diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index 435e1cce0..2f135e18e 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -126,6 +126,11 @@ public function getFiles(): array 'destination' => '.travis.yml', 'template' => 'node/.travis.yml.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'lib/enums/{{ enum.name | caseDash }}.js', + 'template' => 'node/lib/enums/enum.js.twig', + ], ]; } diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 3f6968814..67736ea2a 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -211,6 +211,11 @@ public function getFiles(): array 'destination' => '/src/{{ spec.title | caseUcfirst}}/Services/{{service.name | caseUcfirst}}.php', 'template' => 'php/src/Services/Service.php.twig', ], + [ + 'scope' => 'enum', + 'destination' => '/src/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.php', + 'template' => 'php/src/Enums/Enum.php.twig', + ], ]; } diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index c8d19e639..e0901a60b 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -184,6 +184,11 @@ public function getFiles(): array 'destination' => '.travis.yml', 'template' => 'python/.travis.yml.twig', ], + [ + 'scope' => 'enum', + 'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py', + 'template' => 'python/package/enums/enum.py.twig', + ], ]; } diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 26ec51136..d6838af6c 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -115,6 +115,11 @@ public function getFiles(): array 'destination' => '.travis.yml', 'template' => 'web/.travis.yml.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'src/enums/{{ enum.name | caseDash }}.ts', + 'template' => 'web/src/enums/enum.ts.twig', + ], ]; } diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig index e075e3f0e..b9962b45f 100644 --- a/templates/dart/lib/enums.dart.twig +++ b/templates/dart/lib/enums.dart.twig @@ -1,5 +1,5 @@ library {{ language.params.packageName }}.enums; {% for enum in spec.enum %} -part 'src/enum/{{enum.name | caseSnake}}.dart'; +part 'src/enums/{{enum.name | caseSnake}}.dart'; {% endfor %} \ No newline at end of file diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig new file mode 100644 index 000000000..7f8f5106c --- /dev/null +++ b/templates/node/lib/enums/enum.js.twig @@ -0,0 +1,8 @@ +const {{ enum.name | caseUcfirst | overrideIdentifier }} = { + {% for value in enum.enum %} + {{value}}: '{{ value | caseLower | overrideIdentifier }}' {% if not loop.last %}, + {% endif %} + {% endfor %} +} + +module.exports = {{ enum.name | caseUcfirst | overrideIdentifier }}; \ No newline at end of file diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig new file mode 100644 index 000000000..a0304b38e --- /dev/null +++ b/templates/php/src/Enums/Enum.php.twig @@ -0,0 +1,9 @@ + Date: Thu, 13 Jul 2023 19:05:35 +0530 Subject: [PATCH 04/98] Update src/SDK/SDK.php Co-authored-by: Eldad A. Fux --- src/SDK/SDK.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index ffbe165e4..6d5a513a0 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -641,7 +641,6 @@ public function generate(string $target): void foreach ($this->spec->getServices() as $key => $service) { $methods = $this->spec->getMethods($key); - foreach ($methods as $method) { $params['method'] = $method; $parameters = $method['parameters']['path']; From fde85780a860a278e7db3b17b76827b0f7e2863c Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Thu, 13 Jul 2023 22:04:54 +0530 Subject: [PATCH 05/98] chore: remove appwrite specific method and fetch enum name from swagger --- src/SDK/Language.php | 20 -------------------- src/SDK/SDK.php | 2 +- src/Spec/Swagger2.php | 1 + 3 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/SDK/Language.php b/src/SDK/Language.php index 2c47493d7..3c6ec4a48 100644 --- a/src/SDK/Language.php +++ b/src/SDK/Language.php @@ -98,24 +98,4 @@ protected function toCamelCase($str): string return lcfirst($str); } - public function getEnumType(string $service, string $method): string - { - switch ($service) { - case 'account': - switch ($method) { - case 'createOAuth2Session': - return 'Provider'; - } - case 'avatars': - switch ($method) { - case 'getBrowser': - return 'Browser'; - case 'getCreditCard': - return 'CreditCard'; - case 'getFlag': - return 'Flag'; - } - } - throw new \Exception('Enum type not found for service: ' . $service . ' method: ' . $method); - } } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 6d5a513a0..ec05838f9 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -649,7 +649,7 @@ public function generate(string $target): void // Check if the enum field is defined if ($parameter['enum'] != null) { $params['enum'] = [ - 'name' => $this->language->getEnumType($service['name'], $method['name']), + 'name' => $parameter['enum-name'], 'enum' => $parameter['enum'], ]; $this->render($template, $destination, $block, $params, $minify); diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 9da55eb47..e6f1dafdb 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -228,6 +228,7 @@ public function getMethods($service) break; case 'path': $param['enum'] = $parameter['enum'] ?? null; + $param['enum-name'] = $parameter['x-enum-name'] ?? null; $output['parameters']['path'][] = $param; break; case 'query': From 00019e2c3b33a91f36a960961369180a46533b31 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 14 Jul 2023 10:17:29 +0530 Subject: [PATCH 06/98] chore: fix casing in enums --- src/SDK/SDK.php | 7 ++----- templates/dart/lib/src/enums/enum.dart.twig | 2 +- templates/node/lib/enums/enum.js.twig | 2 +- templates/php/src/Enums/Enum.php.twig | 7 ++++--- templates/python/package/enums/enum.py.twig | 2 +- templates/web/src/enums/enum.ts.twig | 2 +- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index ec05838f9..3da78f08e 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -95,10 +95,10 @@ public function __construct(Language $language, Spec $spec) $this->twig->addExtension(new DebugExtension()); $this->twig->addFilter(new TwigFilter('caseLower', function ($value) { - return strtolower((string)$value); + return strtolower(str_replace('-', '', (string)$value)); })); $this->twig->addFilter(new TwigFilter('caseUpper', function ($value) { - return strtoupper((string)$value); + return strtoupper(str_replace('-', '', (string)$value)); })); $this->twig->addFilter(new TwigFilter('caseUcfirst', function ($value) { return ucfirst($this->helperCamelCase($value)); @@ -140,9 +140,6 @@ public function __construct(Language $language, Spec $spec) $this->twig->addFilter(new TwigFilter('typeName', function ($value) { return $this->language->getTypeName($value); }, ['is_safe' => ['html']])); - $this->twig->addFilter(new TwigFilter('getEnumType', function ($service, $method) { - return $this->language->getEnumType($service, $method); - }, ['is_safe' => ['html']])); $this->twig->addFilter(new TwigFilter('paramDefault', function ($value) { return $this->language->getParamDefault($value); }, ['is_safe' => ['html']])); diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 40b3d51e1..4e2a088d6 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,7 +2,7 @@ part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{value}}{% if not loop.last %}, + {{value | caseCamel}}{% if not loop.last %}, {% endif %} {% endfor %} } \ No newline at end of file diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index 7f8f5106c..e6e2f0b94 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,6 +1,6 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} - {{value}}: '{{ value | caseLower | overrideIdentifier }}' {% if not loop.last %}, + {{ value | caseLower | overrideIdentifier }}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index a0304b38e..9aa69ec1b 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -2,8 +2,9 @@ namespace {{ spec.title | caseUcfirst }}\Enums; -enum {{ enum.name | caseUcfirst | overrideIdentifier }} { +class {{ enum.name | caseUcfirst | overrideIdentifier }} +{ {% for value in enum.enum %} - case {{value}}; + public const {{value | caseUpper | overrideIdentifier}} = '{{value}}'; {% endfor %} -} \ No newline at end of file +} diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 2b09bf574..8966a2303 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,5 +2,5 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {{value}} + {{value | caseUpper | overrideIdentifier}} = {{ value }} {% endfor %} \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index ca48f0f0c..854c57ebc 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,5 +1,5 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{ value | caseUcfirst | overrideIdentifier }}, + {{ value | caseUcfirst | overrideIdentifier }} = '{{ value }}', {% endfor %} } \ No newline at end of file From 2b65a0265473e9e6fe55767540e3374c0183154e Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 14 Jul 2023 11:29:17 +0530 Subject: [PATCH 07/98] chore: add enums deno --- src/SDK/Language/Deno.php | 5 +++++ templates/deno/src/enums/enum.ts.twig | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 templates/deno/src/enums/enum.ts.twig diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 1fdef0c0d..d67a757dc 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -93,6 +93,11 @@ public function getFiles(): array 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', 'template' => 'deno/docs/example.md.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'src/enums/{{ enum.name | caseCamel }}.ts', + 'template' => 'deno/src/enums/enum.ts.twig', + ], ]; } diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig new file mode 100644 index 000000000..e706a1a68 --- /dev/null +++ b/templates/deno/src/enums/enum.ts.twig @@ -0,0 +1,5 @@ +export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { + {% for value in enum.enum %} + {{ value | caseUcfirst | overrideIdentifier }} = '{{ value }}', +{% endfor %} +} \ No newline at end of file From c8b9859d399413b98ac13ab1d60fa706d27a8b72 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 14 Jul 2023 20:50:46 +0530 Subject: [PATCH 08/98] chore: use replace instead of str_replace --- src/SDK/SDK.php | 9 ++++----- src/Spec/Swagger2.php | 2 +- templates/dart/lib/src/enums/enum.dart.twig | 2 +- templates/deno/src/enums/enum.ts.twig | 2 +- templates/node/lib/enums/enum.js.twig | 2 +- templates/php/src/Enums/Enum.php.twig | 2 +- templates/python/package/enums/enum.py.twig | 2 +- templates/web/src/enums/enum.ts.twig | 2 +- 8 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 3da78f08e..88be7ae9e 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -95,10 +95,10 @@ public function __construct(Language $language, Spec $spec) $this->twig->addExtension(new DebugExtension()); $this->twig->addFilter(new TwigFilter('caseLower', function ($value) { - return strtolower(str_replace('-', '', (string)$value)); + return strtolower((string)$value); })); $this->twig->addFilter(new TwigFilter('caseUpper', function ($value) { - return strtoupper(str_replace('-', '', (string)$value)); + return strtoupper((string)$value); })); $this->twig->addFilter(new TwigFilter('caseUcfirst', function ($value) { return ucfirst($this->helperCamelCase($value)); @@ -639,15 +639,14 @@ public function generate(string $target): void $methods = $this->spec->getMethods($key); foreach ($methods as $method) { - $params['method'] = $method; $parameters = $method['parameters']['path']; foreach ($parameters as $parameter) { // Check if the enum field is defined - if ($parameter['enum'] != null) { + if ($parameter['enum-values'] != null) { $params['enum'] = [ 'name' => $parameter['enum-name'], - 'enum' => $parameter['enum'], + 'enum' => $parameter['enum-values'], ]; $this->render($template, $destination, $block, $params, $minify); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index e6f1dafdb..3ee4ccfa9 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -227,7 +227,7 @@ public function getMethods($service) $output['parameters']['header'][] = $param; break; case 'path': - $param['enum'] = $parameter['enum'] ?? null; + $param['enum-values'] = $parameter['enum'] ?? null; $param['enum-name'] = $parameter['x-enum-name'] ?? null; $output['parameters']['path'][] = $param; break; diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 4e2a088d6..8b857c080 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,7 +2,7 @@ part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{value | caseCamel}}{% if not loop.last %}, + {{value | caseCamel | replace({'-': ''})}}{% if not loop.last %}, {% endif %} {% endfor %} } \ No newline at end of file diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig index e706a1a68..74cb8e88a 100644 --- a/templates/deno/src/enums/enum.ts.twig +++ b/templates/deno/src/enums/enum.ts.twig @@ -1,5 +1,5 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{ value | caseUcfirst | overrideIdentifier }} = '{{ value }}', + {{ value | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', {% endfor %} } \ No newline at end of file diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index e6e2f0b94..5e153247b 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,6 +1,6 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} - {{ value | caseLower | overrideIdentifier }}: '{{value}}' {% if not loop.last %}, + {{ value | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index 9aa69ec1b..f60d9e8b6 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -5,6 +5,6 @@ namespace {{ spec.title | caseUcfirst }}\Enums; class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - public const {{value | caseUpper | overrideIdentifier}} = '{{value}}'; + public const {{value | caseUpper | replace({'-': ''})}} = '{{value}}'; {% endfor %} } diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 8966a2303..95c11cfaa 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,5 +2,5 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {{value | caseUpper | overrideIdentifier}} = {{ value }} + {{value | caseUpper | replace({'-': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index 854c57ebc..aa5a197ad 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,5 +1,5 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{ value | caseUcfirst | overrideIdentifier }} = '{{ value }}', + {{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}', {% endfor %} } \ No newline at end of file From 4b2abbfefb68145378719098308c7fb114f80844 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 14 Jul 2023 21:11:06 +0530 Subject: [PATCH 09/98] chore: add support for android and kotlin --- src/SDK/Language/Android.php | 5 +++++ src/SDK/Language/Kotlin.php | 5 +++++ .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 9 +++++++++ .../src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 9 +++++++++ 4 files changed, 28 insertions(+) create mode 100644 templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig create mode 100644 templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig diff --git a/src/SDK/Language/Android.php b/src/SDK/Language/Android.php index 5d3e90bb0..4421bfa90 100644 --- a/src/SDK/Language/Android.php +++ b/src/SDK/Language/Android.php @@ -387,6 +387,11 @@ public function getFiles(): array 'destination' => 'library/src/main/java/io/appwrite/models/{{ definition.name | caseUcfirst }}.kt', 'template' => '/android/library/src/main/java/io/appwrite/models/Model.kt.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'library/src/main/java/io/appwrite/enums/{{ enum.name | caseUcfirst }}.kt', + 'template' => '/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig', + ], ]; } } diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index f6a2af02b..82b02372e 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -418,6 +418,11 @@ public function getFiles(): array 'destination' => '/src/main/kotlin/{{ sdk.namespace | caseSlash }}/models/{{ definition.name | caseUcfirst }}.kt', 'template' => '/kotlin/src/main/kotlin/io/appwrite/models/Model.kt.twig', ], + [ + 'scope' => 'enum', + 'destination' => '/src/main/kotlin/{{ sdk.namespace | caseSlash }}/enums/{{ enum.name | caseUcfirst }}.kt', + 'template' => '/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig', + ], ]; } diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig new file mode 100644 index 000000000..39a5da515 --- /dev/null +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -0,0 +1,9 @@ +package {{ sdk.namespace | caseDot }}.enums + +enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { +{% for value in enum.enum %} + {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, +{% endif %} +{% endfor %} + +} \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig new file mode 100644 index 000000000..39a5da515 --- /dev/null +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -0,0 +1,9 @@ +package {{ sdk.namespace | caseDot }}.enums + +enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { +{% for value in enum.enum %} + {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, +{% endif %} +{% endfor %} + +} \ No newline at end of file From f3e010fa10e76991d56f77ae8c0fea053c10b8ff Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Sat, 15 Jul 2023 12:06:36 +0530 Subject: [PATCH 10/98] chore: export enums dart fixed --- src/SDK/Language.php | 1 - src/SDK/SDK.php | 1 + src/Spec/Spec.php | 7 +++++++ src/Spec/Swagger2.php | 21 +++++++++++++++++++++ templates/dart/lib/enums.dart.twig | 6 +++--- templates/dart/lib/src/enums/enum.dart.twig | 6 +++++- 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/SDK/Language.php b/src/SDK/Language.php index 3c6ec4a48..0a7a259f7 100644 --- a/src/SDK/Language.php +++ b/src/SDK/Language.php @@ -97,5 +97,4 @@ protected function toCamelCase($str): string $str = str_replace(" ", "", $str); return lcfirst($str); } - } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 88be7ae9e..deeaa2a59 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -556,6 +556,7 @@ public function generate(string $target): void 'params' => $this->language->getParams(), ], 'sdk' => $this->getParams(), + 'enums' => $this->spec->getEnumNames(), ]; foreach ($this->language->getFiles() as $file) { diff --git a/src/Spec/Spec.php b/src/Spec/Spec.php index 6ffbbba53..cf22cfa18 100644 --- a/src/Spec/Spec.php +++ b/src/Spec/Spec.php @@ -164,4 +164,11 @@ public function setAttribute($key, $value, $type = self::SET_TYPE_ASSIGN) return $this; } + + /** + * Get EnumNames + * + * @return array + */ + abstract public function getEnumNames(); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 3ee4ccfa9..95c502d0b 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -343,4 +343,25 @@ public function getDefinitions() } return $list; } + + /** + * @return array + */ + public function getEnumNames(): array + { + $list = []; + + foreach ($this->getServices() as $key => $service) { + foreach ($this->getMethods($key) as $method) { + if (isset($method['parameters']) && is_array($method['parameters'])) { + foreach ($method['parameters']['path'] as $parameter) { + if (isset($parameter['enum-name'])) { + $list[] = $parameter['enum-name']; + } + } + } + } + } + return $list; + } } diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig index b9962b45f..3932e5fe0 100644 --- a/templates/dart/lib/enums.dart.twig +++ b/templates/dart/lib/enums.dart.twig @@ -1,5 +1,5 @@ library {{ language.params.packageName }}.enums; -{% for enum in spec.enum %} -part 'src/enums/{{enum.name | caseSnake}}.dart'; -{% endfor %} \ No newline at end of file +{% for enum in enums %} +part 'src/enums/{{enum | caseSnake}}.dart'; +{% endfor %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 8b857c080..91bad8f88 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,7 +2,11 @@ part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{value | caseCamel | replace({'-': ''})}}{% if not loop.last %}, + {{value | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, {% endif %} +{% if loop.last %};{% endif %} {% endfor %} + +final String value; +const {{ enum.name | caseUcfirst | overrideIdentifier }}(this.value); } \ No newline at end of file From 0af2a86f7117d5405e67de4fd5caa24ed32c0378 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 17 Jul 2023 11:17:14 +0530 Subject: [PATCH 11/98] chore: add exports in package.dart.twig --- src/SDK/Language/Dart.php | 5 ----- src/SDK/Language/Flutter.php | 5 ----- templates/dart/lib/enums.dart.twig | 5 ----- templates/dart/lib/package.dart.twig | 4 ++++ templates/dart/lib/src/enums/enum.dart.twig | 2 +- templates/flutter/lib/package.dart.twig | 3 +++ 6 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 templates/dart/lib/enums.dart.twig diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index d44525f27..753d6259f 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -471,11 +471,6 @@ public function getFiles(): array 'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart', 'template' => 'dart/lib/src/enums/enum.dart.twig', ], - [ - 'scope' => 'default', - 'destination' => 'lib/enums.dart', - 'template' => 'dart/lib/enums.dart.twig', - ], ]; } diff --git a/src/SDK/Language/Flutter.php b/src/SDK/Language/Flutter.php index 26f84b8d7..1da9709b5 100644 --- a/src/SDK/Language/Flutter.php +++ b/src/SDK/Language/Flutter.php @@ -335,11 +335,6 @@ public function getFiles(): array 'destination' => 'lib/src/enums/{{ enum.name | caseSnake }}.dart', 'template' => 'dart/lib/src/enums/enum.dart.twig', ], - [ - 'scope' => 'default', - 'destination' => 'lib/enums.dart', - 'template' => 'dart/lib/enums.dart.twig', - ], ]; } } diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig deleted file mode 100644 index 3932e5fe0..000000000 --- a/templates/dart/lib/enums.dart.twig +++ /dev/null @@ -1,5 +0,0 @@ -library {{ language.params.packageName }}.enums; - -{% for enum in enums %} -part 'src/enums/{{enum | caseSnake}}.dart'; -{% endfor %} diff --git a/templates/dart/lib/package.dart.twig b/templates/dart/lib/package.dart.twig index 2ff4077c0..688b80b82 100644 --- a/templates/dart/lib/package.dart.twig +++ b/templates/dart/lib/package.dart.twig @@ -27,3 +27,7 @@ part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; {% endfor %} + +{% for enum in enums %} +part 'src/enums/{{enum | caseSnake}}.dart'; +{% endfor %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 91bad8f88..7d0c31d8c 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -1,4 +1,4 @@ -part of {{ language.params.packageName }}.enums; +part of {{ language.params.packageName }}; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} diff --git a/templates/flutter/lib/package.dart.twig b/templates/flutter/lib/package.dart.twig index 9d92197b1..ca6dc09c8 100644 --- a/templates/flutter/lib/package.dart.twig +++ b/templates/flutter/lib/package.dart.twig @@ -28,4 +28,7 @@ part 'role.dart'; part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; +{% endfor %} +{% for enum in enums %} +part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} \ No newline at end of file From 63f7b83502c12a286614b0db5d6af9c027d6639e Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 17 Jul 2023 12:34:34 +0530 Subject: [PATCH 12/98] chore: export enums in index.ts --- templates/web/src/enums/enum.ts.twig | 2 +- templates/web/src/index.ts.twig | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index aa5a197ad..d284e7648 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,4 +1,4 @@ -export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { +export enum {{ enum.name | caseUcfirst }} { {% for value in enum.enum %} {{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}', {% endfor %} diff --git a/templates/web/src/index.ts.twig b/templates/web/src/index.ts.twig index 75ecd534d..dcee4ebc4 100644 --- a/templates/web/src/index.ts.twig +++ b/templates/web/src/index.ts.twig @@ -6,4 +6,7 @@ export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './c export type { QueryTypes, QueryTypesList } from './query'; export { Permission } from './permission'; export { Role } from './role'; -export { ID } from './id'; \ No newline at end of file +export { ID } from './id'; +{% for enum in enums %} +export { {{ enum | caseUcfirst }} } from './enums/{{enum | caseDash}}'; +{% endfor %} \ No newline at end of file From 5e8d758111c9d6f27934748b324ba94e203c5d74 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 17 Jul 2023 15:02:39 +0530 Subject: [PATCH 13/98] chore: add missing whitelist enums --- src/SDK/SDK.php | 10 +++++----- src/Spec/Swagger2.php | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index deeaa2a59..2594f9a7f 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -640,15 +640,15 @@ public function generate(string $target): void $methods = $this->spec->getMethods($key); foreach ($methods as $method) { - $parameters = $method['parameters']['path']; + $parameters = $method['parameters']['all']; foreach ($parameters as $parameter) { - // Check if the enum field is defined - if ($parameter['enum-values'] != null) { + // Check if the enum field is defined + if (isset($parameter['enum-values'])) { $params['enum'] = [ - 'name' => $parameter['enum-name'], + 'name' => $parameter['enum-name'] ?? $parameter['name'], 'enum' => $parameter['enum-values'], - ]; + ]; $this->render($template, $destination, $block, $params, $minify); } } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 95c502d0b..56eeb80ff 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -221,14 +221,16 @@ public function getMethods($service) } $param['default'] = (is_array($param['default'])) ? json_encode($param['default']) : $param['default']; + if (isset($parameter['enum'])) { + $param['enum-values'] = $parameter['enum']; + $param['enum-name'] = $parameter['x-enum-name']; + } switch ($parameter['in']) { case 'header': $output['parameters']['header'][] = $param; break; case 'path': - $param['enum-values'] = $parameter['enum'] ?? null; - $param['enum-name'] = $parameter['x-enum-name'] ?? null; $output['parameters']['path'][] = $param; break; case 'query': @@ -354,9 +356,9 @@ public function getEnumNames(): array foreach ($this->getServices() as $key => $service) { foreach ($this->getMethods($key) as $method) { if (isset($method['parameters']) && is_array($method['parameters'])) { - foreach ($method['parameters']['path'] as $parameter) { - if (isset($parameter['enum-name'])) { - $list[] = $parameter['enum-name']; + foreach ($method['parameters']['all'] as $parameter) { + if (isset($parameter['enum-values'])) { + $list[] = $parameter['enum-name'] ?? $parameter['name']; } } } From 00bc2f98fe5ebce1b1b575427c0ab23882b8a507 Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Mon, 17 Jul 2023 09:56:30 +0000 Subject: [PATCH 14/98] Create .NET enums template --- src/SDK/Language/DotNet.php | 5 +++++ templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 templates/dotnet/src/Appwrite/Enums/Enums.cs.twig diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 709f56ea5..a15764a4b 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -394,6 +394,11 @@ public function getFiles(): array 'scope' => 'definition', 'destination' => '/src/{{ spec.title | caseUcfirst }}/Models/{{ definition.name | caseUcfirst | overrideIdentifier }}.cs', 'template' => 'dotnet/src/Appwrite/Models/Model.cs.twig', + ], + [ + 'scope' => 'enum', + 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ definition.name | caseUcfirst | overrideIdentifier }}.cs', + 'template' => 'dotnet/src/Appwrite/Enums/Enums.cs.twig', ] ]; } diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig new file mode 100644 index 000000000..b28cb63d3 --- /dev/null +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -0,0 +1,11 @@ +using System; + +namespace {{ spec.title | caseUcfirst }}.Enums +{ + public static class {{ enum.name | caseUcfirst | overrideIdentifier }} + { + {% for value in enum.enum %} + public static string {{ value | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", + {% endfor %} + } +} \ No newline at end of file From 0ffeca4c2a7f427619670fb097f6531714d8bdcc Mon Sep 17 00:00:00 2001 From: Aditya Oberai Date: Mon, 17 Jul 2023 15:33:26 +0530 Subject: [PATCH 15/98] Update src/SDK/Language/DotNet.php Co-authored-by: Bishwajeet Parhi <62933155+2002Bishwajeet@users.noreply.github.com> --- src/SDK/Language/DotNet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index a15764a4b..ea54c5a76 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -397,7 +397,7 @@ public function getFiles(): array ], [ 'scope' => 'enum', - 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ definition.name | caseUcfirst | overrideIdentifier }}.cs', + 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ enum.name | caseUcfirst | overrideIdentifier }}.cs', 'template' => 'dotnet/src/Appwrite/Enums/Enums.cs.twig', ] ]; From 7557829c93a981929a2ae5c1da990e9cf149fb24 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 18 Jul 2023 20:30:26 +0530 Subject: [PATCH 16/98] chore: refactors --- example.php | 10 +++++----- src/SDK/SDK.php | 1 + src/Spec/Swagger2.php | 1 + .../src/main/java/io/appwrite/enums/Enum.kt.twig | 3 ++- templates/dart/lib/src/enums/enum.dart.twig | 3 ++- templates/deno/src/enums/enum.ts.twig | 3 ++- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 3 ++- .../src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 3 ++- templates/node/lib/enums/enum.js.twig | 3 ++- templates/php/src/Enums/Enum.php.twig | 3 ++- templates/python/package/enums/enum.py.twig | 3 ++- templates/web/src/enums/enum.ts.twig | 3 ++- 12 files changed, 25 insertions(+), 14 deletions(-) diff --git a/example.php b/example.php index 6af298baf..8de4c83d5 100644 --- a/example.php +++ b/example.php @@ -37,13 +37,13 @@ function getSSLPage($url) { } // Leave the platform you want uncommented - $platform = 'client'; - // $platform = 'console'; - // $platform = 'server'; +// $platform = 'client'; +// $platform = 'console'; + $platform = 'server'; - $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/master/app/config/specs/swagger2-latest-{$platform}.json"); + $spec = getSSLPage("https://raw.githubusercontent.com/2002bishwajeet/appwrite/feat-whitelist-enums/app/config/specs/swagger2-latest-{$platform}.json"); - if(empty($spec)) { + if (empty($spec)) { throw new Exception('Failed to fetch spec from Appwrite server'); } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 2594f9a7f..f94f35d71 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -648,6 +648,7 @@ public function generate(string $target): void $params['enum'] = [ 'name' => $parameter['enum-name'] ?? $parameter['name'], 'enum' => $parameter['enum-values'], + 'keys' => $parameter['enum-keys'], ]; $this->render($template, $destination, $block, $params, $minify); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 56eeb80ff..f2cce1b06 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -224,6 +224,7 @@ public function getMethods($service) if (isset($parameter['enum'])) { $param['enum-values'] = $parameter['enum']; $param['enum-name'] = $parameter['x-enum-name']; + $param['enum-keys'] = $parameter['x-enum-keys']; } switch ($parameter['in']) { diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 39a5da515..c8f97f1c1 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 7d0c31d8c..29c574c3e 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,7 +2,8 @@ part of {{ language.params.packageName }}; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{value | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, {% endif %} {% if loop.last %};{% endif %} {% endfor %} diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig index 74cb8e88a..b94dd355f 100644 --- a/templates/deno/src/enums/enum.ts.twig +++ b/templates/deno/src/enums/enum.ts.twig @@ -1,5 +1,6 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{ value | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', {% endfor %} } \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index b28cb63d3..6ecf1f02d 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -5,7 +5,8 @@ namespace {{ spec.title | caseUcfirst }}.Enums public static class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - public static string {{ value | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public static string {{ key | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", {% endfor %} } } \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index 39a5da515..c8f97f1c1 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index 5e153247b..cb70680b1 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,6 +1,7 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} - {{ value | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index f60d9e8b6..b3d809dd8 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -5,6 +5,7 @@ namespace {{ spec.title | caseUcfirst }}\Enums; class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - public const {{value | caseUpper | replace({'-': ''})}} = '{{value}}'; + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public const {{ key | caseUpper | replace({'-': ''})}} = '{{value}}'; {% endfor %} } diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 95c11cfaa..f7b6cbcfb 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,5 +2,6 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}} = "{{ value }}" + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index d284e7648..d9366b495 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,5 +1,6 @@ export enum {{ enum.name | caseUcfirst }} { {% for value in enum.enum %} - {{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}', + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUcfirst | replace({'-': ''})}} = '{{ value }}', {% endfor %} } \ No newline at end of file From ea06f3778fd2bc3c096ad9af9743cc56887a4862 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 18 Jul 2023 21:17:49 +0530 Subject: [PATCH 17/98] Revert "chore: refactors" This reverts commit 7557829c93a981929a2ae5c1da990e9cf149fb24. --- src/SDK/SDK.php | 1 - src/Spec/Swagger2.php | 1 - .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 3 +-- templates/dart/lib/src/enums/enum.dart.twig | 3 +-- templates/deno/src/enums/enum.ts.twig | 3 +-- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 3 +-- .../kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 3 +-- templates/node/lib/enums/enum.js.twig | 3 +-- templates/php/src/Enums/Enum.php.twig | 3 +-- templates/python/package/enums/enum.py.twig | 3 +-- templates/web/src/enums/enum.ts.twig | 3 +-- 11 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index f94f35d71..2594f9a7f 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -648,7 +648,6 @@ public function generate(string $target): void $params['enum'] = [ 'name' => $parameter['enum-name'] ?? $parameter['name'], 'enum' => $parameter['enum-values'], - 'keys' => $parameter['enum-keys'], ]; $this->render($template, $destination, $block, $params, $minify); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index f2cce1b06..56eeb80ff 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -224,7 +224,6 @@ public function getMethods($service) if (isset($parameter['enum'])) { $param['enum-values'] = $parameter['enum']; $param['enum-name'] = $parameter['x-enum-name']; - $param['enum-keys'] = $parameter['x-enum-keys']; } switch ($parameter['in']) { diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index c8f97f1c1..39a5da515 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -2,8 +2,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 29c574c3e..7d0c31d8c 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,8 +2,7 @@ part of {{ language.params.packageName }}; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} -{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, + {{value | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, {% endif %} {% if loop.last %};{% endif %} {% endfor %} diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig index b94dd355f..74cb8e88a 100644 --- a/templates/deno/src/enums/enum.ts.twig +++ b/templates/deno/src/enums/enum.ts.twig @@ -1,6 +1,5 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', + {{ value | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', {% endfor %} } \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 6ecf1f02d..b28cb63d3 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -5,8 +5,7 @@ namespace {{ spec.title | caseUcfirst }}.Enums public static class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static string {{ key | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", + public static string {{ value | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", {% endfor %} } } \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index c8f97f1c1..39a5da515 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -2,8 +2,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index cb70680b1..5e153247b 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,7 +1,6 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, + {{ value | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index b3d809dd8..f60d9e8b6 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -5,7 +5,6 @@ namespace {{ spec.title | caseUcfirst }}\Enums; class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const {{ key | caseUpper | replace({'-': ''})}} = '{{value}}'; + public const {{value | caseUpper | replace({'-': ''})}} = '{{value}}'; {% endfor %} } diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index f7b6cbcfb..95c11cfaa 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,6 +2,5 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}} = "{{ value }}" + {{value | caseUpper | replace({'-': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index d9366b495..d284e7648 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,6 +1,5 @@ export enum {{ enum.name | caseUcfirst }} { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUcfirst | replace({'-': ''})}} = '{{ value }}', + {{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}', {% endfor %} } \ No newline at end of file From d38abfbcead9335885ad8ab06da496758609351d Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 18 Jul 2023 22:02:53 +0530 Subject: [PATCH 18/98] Revert "Revert "chore: refactors"" This reverts commit ea06f3778fd2bc3c096ad9af9743cc56887a4862. --- src/SDK/SDK.php | 1 + src/Spec/Swagger2.php | 1 + .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 3 ++- templates/dart/lib/src/enums/enum.dart.twig | 3 ++- templates/deno/src/enums/enum.ts.twig | 3 ++- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 3 ++- .../kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 3 ++- templates/node/lib/enums/enum.js.twig | 3 ++- templates/php/src/Enums/Enum.php.twig | 3 ++- templates/python/package/enums/enum.py.twig | 3 ++- templates/web/src/enums/enum.ts.twig | 3 ++- 11 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 2594f9a7f..f94f35d71 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -648,6 +648,7 @@ public function generate(string $target): void $params['enum'] = [ 'name' => $parameter['enum-name'] ?? $parameter['name'], 'enum' => $parameter['enum-values'], + 'keys' => $parameter['enum-keys'], ]; $this->render($template, $destination, $block, $params, $minify); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 56eeb80ff..f2cce1b06 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -224,6 +224,7 @@ public function getMethods($service) if (isset($parameter['enum'])) { $param['enum-values'] = $parameter['enum']; $param['enum-name'] = $parameter['x-enum-name']; + $param['enum-keys'] = $parameter['x-enum-keys']; } switch ($parameter['in']) { diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 39a5da515..c8f97f1c1 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 7d0c31d8c..29c574c3e 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -2,7 +2,8 @@ part of {{ language.params.packageName }}; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{value | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, {% endif %} {% if loop.last %};{% endif %} {% endfor %} diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig index 74cb8e88a..b94dd355f 100644 --- a/templates/deno/src/enums/enum.ts.twig +++ b/templates/deno/src/enums/enum.ts.twig @@ -1,5 +1,6 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {{ value | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', {% endfor %} } \ No newline at end of file diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index b28cb63d3..6ecf1f02d 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -5,7 +5,8 @@ namespace {{ spec.title | caseUcfirst }}.Enums public static class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - public static string {{ value | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public static string {{ key | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", {% endfor %} } } \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index 39a5da515..c8f97f1c1 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -2,7 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index 5e153247b..cb70680b1 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,6 +1,7 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} - {{ value | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index f60d9e8b6..b3d809dd8 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -5,6 +5,7 @@ namespace {{ spec.title | caseUcfirst }}\Enums; class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - public const {{value | caseUpper | replace({'-': ''})}} = '{{value}}'; + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public const {{ key | caseUpper | replace({'-': ''})}} = '{{value}}'; {% endfor %} } diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 95c11cfaa..f7b6cbcfb 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,5 +2,6 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {{value | caseUpper | replace({'-': ''})}} = "{{ value }}" + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index d284e7648..d9366b495 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,5 +1,6 @@ export enum {{ enum.name | caseUcfirst }} { {% for value in enum.enum %} - {{ value | caseUcfirst | replace({'-': ''})}} = '{{ value }}', + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUcfirst | replace({'-': ''})}} = '{{ value }}', {% endfor %} } \ No newline at end of file From b1beb30f7ec3ab73c1a832b96c37d658bb6c9fa0 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 18 Jul 2023 22:06:16 +0530 Subject: [PATCH 19/98] revert example.php --- example.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example.php b/example.php index 8de4c83d5..62ab280f2 100644 --- a/example.php +++ b/example.php @@ -38,12 +38,12 @@ function getSSLPage($url) { // Leave the platform you want uncommented // $platform = 'client'; -// $platform = 'console'; - $platform = 'server'; + $platform = 'console'; + // $platform = 'server'; - $spec = getSSLPage("https://raw.githubusercontent.com/2002bishwajeet/appwrite/feat-whitelist-enums/app/config/specs/swagger2-latest-{$platform}.json"); + $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/master/app/config/specs/swagger2-latest-{$platform}.json"); - if (empty($spec)) { + if(empty($spec)) { throw new Exception('Failed to fetch spec from Appwrite server'); } From f7bb7e921190bec69d10ee5bd57673b2c6dde2d5 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi <62933155+2002Bishwajeet@users.noreply.github.com> Date: Wed, 19 Jul 2023 16:31:59 +0530 Subject: [PATCH 20/98] Update templates/dart/lib/package.dart.twig Co-authored-by: Damodar Lohani --- templates/dart/lib/package.dart.twig | 1 - 1 file changed, 1 deletion(-) diff --git a/templates/dart/lib/package.dart.twig b/templates/dart/lib/package.dart.twig index 688b80b82..0b0942d8e 100644 --- a/templates/dart/lib/package.dart.twig +++ b/templates/dart/lib/package.dart.twig @@ -27,7 +27,6 @@ part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; {% endfor %} - {% for enum in enums %} part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} From 3d475bdcc407d266af632994dc217cb874fbc2ce Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 21 Jul 2023 23:59:59 +0530 Subject: [PATCH 21/98] change to camelCase --- src/SDK/SDK.php | 8 ++++---- src/Spec/Swagger2.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index f94f35d71..639fa1247 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -644,11 +644,11 @@ public function generate(string $target): void foreach ($parameters as $parameter) { // Check if the enum field is defined - if (isset($parameter['enum-values'])) { + if (isset($parameter['enumValues'])) { $params['enum'] = [ - 'name' => $parameter['enum-name'] ?? $parameter['name'], - 'enum' => $parameter['enum-values'], - 'keys' => $parameter['enum-keys'], + 'name' => $parameter['enumName'] ?? $parameter['name'], + 'enum' => $parameter['enumValues'], + 'keys' => $parameter['enumKeys'], ]; $this->render($template, $destination, $block, $params, $minify); } diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index f2cce1b06..4cad9f1eb 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -222,9 +222,9 @@ public function getMethods($service) $param['default'] = (is_array($param['default'])) ? json_encode($param['default']) : $param['default']; if (isset($parameter['enum'])) { - $param['enum-values'] = $parameter['enum']; - $param['enum-name'] = $parameter['x-enum-name']; - $param['enum-keys'] = $parameter['x-enum-keys']; + $param['enumValues'] = $parameter['enum']; + $param['enumName'] = $parameter['x-enum-name']; + $param['enumKeys'] = $parameter['x-enum-keys']; } switch ($parameter['in']) { @@ -358,8 +358,8 @@ public function getEnumNames(): array foreach ($this->getMethods($key) as $method) { if (isset($method['parameters']) && is_array($method['parameters'])) { foreach ($method['parameters']['all'] as $parameter) { - if (isset($parameter['enum-values'])) { - $list[] = $parameter['enum-name'] ?? $parameter['name']; + if (isset($parameter['enumValues'])) { + $list[] = $parameter['enumName'] ?? $parameter['name']; } } } From 7065a77381d2e74e0cc8eee20759ef0b4179be41 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Sat, 22 Jul 2023 00:26:32 +0530 Subject: [PATCH 22/98] feat: docs --- templates/android/docs/java/example.md.twig | 2 +- templates/android/docs/kotlin/example.md.twig | 2 +- .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 2 +- templates/dart/docs/example.md.twig | 4 ++-- templates/deno/docs/example.md.twig | 2 +- templates/dotnet/docs/example.md.twig | 2 +- templates/kotlin/docs/java/example.md.twig | 2 +- templates/kotlin/docs/kotlin/example.md.twig | 2 +- .../kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- templates/node/docs/example.md.twig | 2 +- templates/node/lib/enums/enum.js.twig | 2 +- templates/php/docs/example.md.twig | 2 +- templates/php/src/Enums/Enum.php.twig | 2 +- templates/python/docs/example.md.twig | 2 +- templates/python/package/enums/enum.py.twig | 2 +- templates/web/docs/example.md.twig | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) diff --git a/templates/android/docs/java/example.md.twig b/templates/android/docs/java/example.md.twig index 23f797098..4c9a69105 100644 --- a/templates/android/docs/java/example.md.twig +++ b/templates/android/docs/java/example.md.twig @@ -26,7 +26,7 @@ Client client = new Client(context) {% for parameter in method.parameters.all %} {% if parameter.required %} - {{ parameter | paramExample }}{% if not loop.last %},{% endif %} + {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/android/docs/kotlin/example.md.twig b/templates/android/docs/kotlin/example.md.twig index 8acb6e64a..b44cc2b11 100644 --- a/templates/android/docs/kotlin/example.md.twig +++ b/templates/android/docs/kotlin/example.md.twig @@ -18,7 +18,7 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) {% for parameter in method.parameters.all %} {% if parameter.required %} - {{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %} + {{parameter.name}} = {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index c8f97f1c1..47576854b 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':'_'})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/dart/docs/example.md.twig b/templates/dart/docs/example.md.twig index 5e2afae03..b0f129138 100644 --- a/templates/dart/docs/example.md.twig +++ b/templates/dart/docs/example.md.twig @@ -22,7 +22,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }}, + {{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else%}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); @@ -32,4 +32,4 @@ void main() { // Init SDK }).catchError((error) { print(error.response); }); -} \ No newline at end of file +}} \ No newline at end of file diff --git a/templates/deno/docs/example.md.twig b/templates/deno/docs/example.md.twig index 55f3735ee..e78c1fbf6 100644 --- a/templates/deno/docs/example.md.twig +++ b/templates/deno/docs/example.md.twig @@ -19,7 +19,7 @@ client {% endif %} -let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}); +let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/dotnet/docs/example.md.twig b/templates/dotnet/docs/example.md.twig index 2ce25f701..48aea6186 100644 --- a/templates/dotnet/docs/example.md.twig +++ b/templates/dotnet/docs/example.md.twig @@ -15,4 +15,4 @@ var {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client {% if method.method != 'delete' %}{% if method.type == 'location' %}byte[]{% else %}{{ method.responseModel | caseUcfirst | overrideIdentifier }}{% endif %} result = {% endif %}await {{ service.name | caseCamel }}.{{ method.name | caseUcfirst }}({% if method.parameters.all | length == 0 %});{% endif %} {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %},{% endif %} - {{ parameter.name }}: {{ parameter | paramExample }}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} diff --git a/templates/kotlin/docs/java/example.md.twig b/templates/kotlin/docs/java/example.md.twig index 75508a1ff..a5e622ca4 100644 --- a/templates/kotlin/docs/java/example.md.twig +++ b/templates/kotlin/docs/java/example.md.twig @@ -26,7 +26,7 @@ Client client = new Client() {% for parameter in method.parameters.all %} {% if parameter.required %} - {{ parameter | paramExample }}{% if not loop.last %},{% endif %} + {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index 8acb6e64a..cc662fecb 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -18,7 +18,7 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) {% for parameter in method.parameters.all %} {% if parameter.required %} - {{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %} + {{parameter.name}} = {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index c8f97f1c1..a56055ce5 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}}('{{value}}'){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ': '_'})}}('{{value}}'){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/node/docs/example.md.twig b/templates/node/docs/example.md.twig index 9c0a7a260..db06dbd04 100644 --- a/templates/node/docs/example.md.twig +++ b/templates/node/docs/example.md.twig @@ -18,7 +18,7 @@ client {% endfor %}; {% endif %} -const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}); +const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | replace({'-': '',' ': ''}) }}{% else%}{{ parameter | paramExample}}{% endif %}{% endif %}{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index cb70680b1..e9afe841d 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,7 +1,7 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseLower | replace({'-': ''})}}: '{{value}}' {% if not loop.last %}, + {{ key | caseLower | replace({'-': '',' ': ''})}}: '{{value}}' {% if not loop.last %}, {% endif %} {% endfor %} } diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index 8936a48d3..6aeb3d88d 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -20,4 +20,4 @@ $client {% endif %} ${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); -$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}); \ No newline at end of file +$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); \ No newline at end of file diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index b3d809dd8..66c0afd79 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,6 +6,6 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const {{ key | caseUpper | replace({'-': ''})}} = '{{value}}'; + public const {{ key | caseUpper | replace({'-': '',' ': '_'})}} = '{{value}}'; {% endfor %} } diff --git a/templates/python/docs/example.md.twig b/templates/python/docs/example.md.twig index aa291a705..537b25aec 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -18,4 +18,4 @@ client = Client() {% endif %} {{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) -result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}) +result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index f7b6cbcfb..0358d0549 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -3,5 +3,5 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': ''})}} = "{{ value }}" + {{ key | caseUpper | replace({'-': '',' ': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file diff --git a/templates/web/docs/example.md.twig b/templates/web/docs/example.md.twig index 0d5862963..37c5bcd63 100644 --- a/templates/web/docs/example.md.twig +++ b/templates/web/docs/example.md.twig @@ -16,7 +16,7 @@ client {% endif %} {% if method.type == 'webAuth' %}// Go to OAuth provider login page {% endif %} -{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}); +{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); {% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}console.log(result); // Resource URL{% else %}promise.then(function (response) { console.log(response); // Success From 405bceb4a8e8b2409936774444bc19ac3e8e43e5 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 24 Jul 2023 13:56:55 +0530 Subject: [PATCH 23/98] chore: fix doc generation flutter and web --- templates/flutter/docs/example.md.twig | 6 +++--- templates/web/docs/example.md.twig | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/flutter/docs/example.md.twig b/templates/flutter/docs/example.md.twig index db87c778c..fe0c3d629 100644 --- a/templates/flutter/docs/example.md.twig +++ b/templates/flutter/docs/example.md.twig @@ -23,7 +23,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel }}: {{ parameter | paramExample }}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}).then((bytes) { final file = File('path_to_file/filename.ext'); @@ -40,7 +40,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample }}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %} ), //works for both public file and private file, for private files you need to be logged in @@ -58,7 +58,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel }}: {{ parameter | paramExample }}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); diff --git a/templates/web/docs/example.md.twig b/templates/web/docs/example.md.twig index 37c5bcd63..ff1bc6f2c 100644 --- a/templates/web/docs/example.md.twig +++ b/templates/web/docs/example.md.twig @@ -1,4 +1,4 @@ -import {{ '{' }} Client, {{service.name | caseUcfirst}} {{ '}' }} from "{{ language.params.npmPackage }}"; +import {{ '{' }} Client, {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName | caseUcfirst}},{% endif %}{% endif %}{% endfor %} {{service.name | caseUcfirst}} {{ '}' }} from "{{ language.params.npmPackage }}"; const client = new Client(); From 2267f4c80b9e319d7e9a06a2d44299fa0141a4d3 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 24 Jul 2023 19:14:25 +0530 Subject: [PATCH 24/98] chore: fix import doc deno python php dotnet --- src/SDK/Language/Deno.php | 2 +- templates/deno/mod.ts.twig | 6 ++++++ templates/dotnet/docs/example.md.twig | 3 +++ templates/php/docs/example.md.twig | 4 ++++ templates/python/docs/example.md.twig | 3 +++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index d67a757dc..468af6ca7 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -95,7 +95,7 @@ public function getFiles(): array ], [ 'scope' => 'enum', - 'destination' => 'src/enums/{{ enum.name | caseCamel }}.ts', + 'destination' => 'src/enums/{{ enum.name | caseDash }}.ts', 'template' => 'deno/src/enums/enum.ts.twig', ], ]; diff --git a/templates/deno/mod.ts.twig b/templates/deno/mod.ts.twig index 2878b6360..4d6e5bab7 100644 --- a/templates/deno/mod.ts.twig +++ b/templates/deno/mod.ts.twig @@ -8,6 +8,9 @@ import { {{spec.title | caseUcfirst}}Exception } from "./src/exception.ts"; {% for service in spec.services %} import { {{service.name | caseUcfirst}} } from "./src/services/{{service.name | caseDash}}.ts"; {% endfor %} +{% for enum in enums %} +import { {{enum | caseUcfirst}} } from "./src/enums/{{enum | caseDash}}.ts"; +{% endfor %} export { Client, @@ -20,6 +23,9 @@ export { {% for service in spec.services %} {{service.name | caseUcfirst}}, {% endfor %} +{% for enum in enums %} + {{enum | caseUcfirst}}, +{% endfor %} }; export type { Models } from "./src/models.d.ts"; diff --git a/templates/dotnet/docs/example.md.twig b/templates/dotnet/docs/example.md.twig index 48aea6186..d6c1208e4 100644 --- a/templates/dotnet/docs/example.md.twig +++ b/templates/dotnet/docs/example.md.twig @@ -1,6 +1,9 @@ using {{ spec.title | caseUcfirst }}; using {{ spec.title | caseUcfirst }}.Services; using {{ spec.title | caseUcfirst }}.Models; +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +using {{ spec.title | caseUcfirst }}.Enums; +{% endif %}{% endfor %} var client = new Client() {% if method.auth|length > 0 %} diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index 6aeb3d88d..6430202fe 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -5,6 +5,10 @@ use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\InputFile; {% endif %} use {{ spec.title | caseUcfirst }}\Services\{{ service.name | caseUcfirst }}; +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}using {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};{% endif %} + +{% endif %}{% endfor %} $client = new Client(); diff --git a/templates/python/docs/example.md.twig b/templates/python/docs/example.md.twig index 537b25aec..b3394e4c1 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -3,6 +3,9 @@ from {{ spec.title | caseSnake }}.client import Client from {{ spec.title | caseSnake }}.input_file import InputFile {% endif %} from {{ spec.title | caseSnake }}.services.{{ service.name | caseSnake }} import {{ service.name | caseUcfirst }} +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}from {{ spec.title | caseUcfirst }}.enums import {{parameter.enumName | caseUcfirst}},{% endif %} +{% endif %}{% endfor %} client = Client() From 70e78d617f1c5c8f2bd21fcf075f018f7e394787 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 24 Jul 2023 19:20:49 +0530 Subject: [PATCH 25/98] chore: fix node import --- templates/node/index.js.twig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/node/index.js.twig b/templates/node/index.js.twig index b82be2323..ddd31be72 100644 --- a/templates/node/index.js.twig +++ b/templates/node/index.js.twig @@ -8,6 +8,9 @@ const {{spec.title | caseUcfirst}}Exception = require('./lib/exception.js'); {% for service in spec.services %} const {{service.name | caseUcfirst}} = require('./lib/services/{{service.name | caseDash}}.js'); {% endfor %} +{% for enum in enums %} +const {{enum | caseUcfirst}} = require("./lib/enums/{{enum | caseDash}}.js"); +{% endfor %} module.exports = { Client, @@ -19,5 +22,7 @@ module.exports = { {{spec.title | caseUcfirst}}Exception, {% for service in spec.services %} {{service.name | caseUcfirst}}, +{% endfor %}{% for enum in enums %} + {{ enum | caseUcfirst }}, {% endfor %} }; From 549ab8c017fd809263f0958383921227f1f45ddd Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 24 Jul 2023 19:33:47 +0530 Subject: [PATCH 26/98] chore: add import doc to kotlin and android --- templates/android/docs/java/example.md.twig | 4 ++++ templates/android/docs/kotlin/example.md.twig | 4 ++++ templates/kotlin/docs/java/example.md.twig | 4 ++++ templates/kotlin/docs/kotlin/example.md.twig | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/templates/android/docs/java/example.md.twig b/templates/android/docs/java/example.md.twig index 4c9a69105..710cc6dcd 100644 --- a/templates/android/docs/java/example.md.twig +++ b/templates/android/docs/java/example.md.twig @@ -4,6 +4,10 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback; import {{ sdk.namespace | caseDot }}.models.InputFile; {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}; +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} + +{% endif %}{% endfor %} Client client = new Client(context) {% if method.auth|length > 0 %} diff --git a/templates/android/docs/kotlin/example.md.twig b/templates/android/docs/kotlin/example.md.twig index b44cc2b11..4e7a1f721 100644 --- a/templates/android/docs/kotlin/example.md.twig +++ b/templates/android/docs/kotlin/example.md.twig @@ -3,6 +3,10 @@ import {{ sdk.namespace | caseDot }}.Client import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} + +{% endif %}{% endfor %} val client = Client(context) {% if method.auth|length > 0 %} diff --git a/templates/kotlin/docs/java/example.md.twig b/templates/kotlin/docs/java/example.md.twig index a5e622ca4..d597795bb 100644 --- a/templates/kotlin/docs/java/example.md.twig +++ b/templates/kotlin/docs/java/example.md.twig @@ -4,6 +4,10 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback; import {{ sdk.namespace | caseDot }}.models.InputFile; {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}; +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} + +{% endif %}{% endfor %} Client client = new Client() {% if method.auth|length > 0 %} diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index cc662fecb..8e48364ea 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -3,6 +3,10 @@ import {{ sdk.namespace | caseDot }}.Client import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} +{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} + +{% endif %}{% endfor %} val client = Client(context) {% if method.auth|length > 0 %} From fb177454fdc1b2b993494c78cf91c8e933279ab9 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 24 Jul 2023 20:02:39 +0530 Subject: [PATCH 27/98] feat: swift +App --- src/SDK/Language/Apple.php | 5 +++++ src/SDK/Language/Swift.php | 5 +++++ templates/swift/Sources/Enums/Enum.swift.twig | 5 +++++ templates/swift/docs/example.md.twig | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 templates/swift/Sources/Enums/Enum.swift.twig diff --git a/src/SDK/Language/Apple.php b/src/SDK/Language/Apple.php index e3515de48..eb452ce1e 100644 --- a/src/SDK/Language/Apple.php +++ b/src/SDK/Language/Apple.php @@ -60,6 +60,11 @@ public function getFiles(): array 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/WebSockets/WebSocketClientError.swift', 'template' => '/swift/Sources/WebSockets/WebSocketClientError.swift.twig', ], + [ + 'scope' => 'enum', + 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.swift', + 'template' => '/swift/Sources/Enums/Enum.swift.twig', + ], // Config for project example-swiftui [ 'scope' => 'default', diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 9b2e08798..504214efd 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -284,6 +284,11 @@ public function getFiles(): array 'destination' => '/Sources/{{ spec.title | caseUcfirst}}Models/{{ definition.name | caseUcfirst }}.swift', 'template' => '/swift/Sources/Models/Model.swift.twig', ], + [ + 'scope' => 'enum', + 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.swift', + 'template' => '/swift/Sources/Enums/Enum.swift.twig', + ] ]; } diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig new file mode 100644 index 000000000..341164ab4 --- /dev/null +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -0,0 +1,5 @@ +enum {{ enum.name | caseUcfirst | overrideIdentifier }} : String { +{% for value in enum.enum %} + {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + case {{ key | caseCamel | replace({'-': ''})}} = '{{ value }}' +{% endfor %} diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index 2d4f478db..afb7b368c 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -15,7 +15,7 @@ let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% i let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} {% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} - {{parameter.name}}: {{ parameter | paramExample | escapeKeyword }}{% if not loop.last %},{% endif %} + {{parameter.name}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample | escapeKeyword }}{% endif %}{% if not loop.last %},{% endif %} {% if loop.last %} ) From 0969f0cbbbf766d3f8e4ab370b00654402cbd717 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 26 Jul 2023 10:45:03 +0530 Subject: [PATCH 28/98] refactor: single quotes to double quotes in kotlin --- .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 2 +- templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 47576854b..14d2c1169 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_'})}}('{{value}}'){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':'_'})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index a56055ce5..b81ab72e6 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': '_'})}}('{{value}}'){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ': '_'})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} From ca3882f8c38bfda90c7f57d36ffb6a35dd5eb03b Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 26 Jul 2023 10:48:28 +0530 Subject: [PATCH 29/98] chore: remove ; --- templates/android/docs/kotlin/example.md.twig | 2 +- templates/kotlin/docs/kotlin/example.md.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/android/docs/kotlin/example.md.twig b/templates/android/docs/kotlin/example.md.twig index 4e7a1f721..2b0c44439 100644 --- a/templates/android/docs/kotlin/example.md.twig +++ b/templates/android/docs/kotlin/example.md.twig @@ -4,7 +4,7 @@ import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}}{% endif %} {% endif %}{% endfor %} diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index 8e48364ea..16e8d525f 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -4,7 +4,7 @@ import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} +{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}}{% endif %} {% endif %}{% endfor %} From cda11c8df942e687fbb3a6f6a490a09271cfe02e Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 26 Jul 2023 10:52:26 +0530 Subject: [PATCH 30/98] chore: add readonly c# --- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 6ecf1f02d..12a73f004 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -6,7 +6,8 @@ namespace {{ spec.title | caseUcfirst }}.Enums { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static string {{ key | caseUcfirst | replace({'-': ''}) }} = "{{ value }}", + public static readonly string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}" + {% if not loop.last %},{% endif %} {% endfor %} } } \ No newline at end of file From d3b42203f0ad6b52f9e7e82845724f078d509d64 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 26 Jul 2023 10:57:11 +0530 Subject: [PATCH 31/98] Strip space instead of adding underscore --- .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 2 +- templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 14d2c1169..71959357e 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_'})}}("{{value}}"){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index b81ab72e6..1322953de 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': '_'})}}("{{value}}"){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ': ''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} From bded653b9bf3272ac629702938bbc62761a5ddc7 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Wed, 26 Jul 2023 11:18:48 +0530 Subject: [PATCH 32/98] refactor: convert this to module --- src/SDK/Language/Swift.php | 2 +- templates/swift/docs/example.md.twig | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 504214efd..a4d731808 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -286,7 +286,7 @@ public function getFiles(): array ], [ 'scope' => 'enum', - 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.swift', + 'destination' => '/Sources/{{ spec.title | caseUcfirst}}Enums/{{ enum.name | caseUcfirst }}.swift', 'template' => '/swift/Sources/Enums/Enum.swift.twig', ] ]; diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index afb7b368c..31eca4603 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -1,4 +1,9 @@ import Appwrite +{% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} +{% if parameter.enumValues | length > 0 %} +import AppwriteEnums +{% endif %} +{% endfor %} let client = Client() {% if method.auth|length > 0 %} From 899b5b837c240ff4e7feadbd09908e953b33415f Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 1 Aug 2023 11:12:30 +0530 Subject: [PATCH 33/98] add Type support flutter,dart --- templates/dart/lib/services/service.dart.twig | 2 +- templates/flutter/lib/services/service.dart.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dart/lib/services/service.dart.twig b/templates/dart/lib/services/service.dart.twig index 00141e5a3..ff6ee2432 100644 --- a/templates/dart/lib/services/service.dart.twig +++ b/templates/dart/lib/services/service.dart.twig @@ -1,5 +1,5 @@ part of {{ language.params.packageName }}; -{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} +{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter.enumName ?? parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} {% macro method_parameters(parameters, consumes) %} {% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %} {% endmacro %} diff --git a/templates/flutter/lib/services/service.dart.twig b/templates/flutter/lib/services/service.dart.twig index 0cc609d03..ce5a7bbee 100644 --- a/templates/flutter/lib/services/service.dart.twig +++ b/templates/flutter/lib/services/service.dart.twig @@ -1,5 +1,5 @@ part of {{ language.params.packageName }}; -{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} +{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter.enumName ?? parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} {% macro method_parameters(parameters, consumes) %} {% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %} {% endmacro %} From 328fa6bbbd51459f74a0478f8248198ab86f23e8 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Tue, 1 Aug 2023 13:19:20 +0530 Subject: [PATCH 34/98] add enum types in services --- src/SDK/Language/Dart.php | 4 ++++ src/SDK/Language/Deno.php | 4 ++++ src/SDK/Language/DotNet.php | 4 ++++ src/SDK/Language/JS.php | 4 ++++ src/SDK/Language/Kotlin.php | 4 ++++ src/SDK/Language/PHP.php | 4 ++++ src/SDK/Language/Swift.php | 4 ++++ src/SDK/Language/Web.php | 4 ++++ templates/dart/lib/services/service.dart.twig | 2 +- templates/flutter/lib/services/service.dart.twig | 2 +- templates/php/docs/example.md.twig | 2 +- templates/php/src/Services/Service.php.twig | 3 +++ 12 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 753d6259f..bca1f3bbe 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -121,6 +121,10 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName'] . ' '; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: return 'int'; diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 468af6ca7..84327921b 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -107,6 +107,10 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: return 'number'; diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 6b34dfcc3..84c92e7ad 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -151,6 +151,10 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: return 'long'; diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index c41727e36..d3d51b133 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -124,6 +124,10 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: case self::TYPE_NUMBER: diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index f5db8fa96..ac0ca0ebd 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -105,6 +105,10 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: return 'Long'; diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index bb81a6ea6..750da6cdd 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -227,6 +227,10 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName'] . ' '; + } + switch ($parameter['type']) { case self::TYPE_STRING: $type = 'string'; diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index a4d731808..ed08dc969 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -298,6 +298,10 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: return 'Int'; diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index d6838af6c..08d187a73 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -179,6 +179,10 @@ public function getParamExample(array $param): string public function getTypeName(array $parameter, array $method = []): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } + switch ($parameter['type']) { case self::TYPE_INTEGER: case self::TYPE_NUMBER: diff --git a/templates/dart/lib/services/service.dart.twig b/templates/dart/lib/services/service.dart.twig index ff6ee2432..00141e5a3 100644 --- a/templates/dart/lib/services/service.dart.twig +++ b/templates/dart/lib/services/service.dart.twig @@ -1,5 +1,5 @@ part of {{ language.params.packageName }}; -{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter.enumName ?? parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} +{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} {% macro method_parameters(parameters, consumes) %} {% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %} {% endmacro %} diff --git a/templates/flutter/lib/services/service.dart.twig b/templates/flutter/lib/services/service.dart.twig index ce5a7bbee..0cc609d03 100644 --- a/templates/flutter/lib/services/service.dart.twig +++ b/templates/flutter/lib/services/service.dart.twig @@ -1,5 +1,5 @@ part of {{ language.params.packageName }}; -{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter.enumName ?? parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} +{% macro parameter(parameter) %}{% if parameter.required %}required {% endif %}{{ parameter | typeName }}{% if not parameter.required or parameter.nullable %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %} {% macro method_parameters(parameters, consumes) %} {% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %} {% endmacro %} diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index 6430202fe..ab296d8da 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -6,7 +6,7 @@ use {{ spec.title | caseUcfirst }}\InputFile; {% endif %} use {{ spec.title | caseUcfirst }}\Services\{{ service.name | caseUcfirst }}; {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}using {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};{% endif %} +{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};{% endif %} {% endif %}{% endfor %} diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index 3e110cffe..cc8dbf65b 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -6,6 +6,9 @@ use {{ spec.title | caseUcfirst }}\{{spec.title | caseUcfirst}}Exception; use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\Service; use {{ spec.title | caseUcfirst }}\InputFile; +{% for method in service.methods %}{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}}; +{% endif %} +{% endif %}{% endfor %}{% endfor %} class {{ service.name | caseUcfirst }} extends Service { From 1d827eecc80a592beeb5cf16aa950e58ea79a95d Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Thu, 3 Aug 2023 11:21:27 +0530 Subject: [PATCH 35/98] fix imports php --- templates/php/src/Services/Service.php.twig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index cc8dbf65b..c6b58a367 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -6,8 +6,7 @@ use {{ spec.title | caseUcfirst }}\{{spec.title | caseUcfirst}}Exception; use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\Service; use {{ spec.title | caseUcfirst }}\InputFile; -{% for method in service.methods %}{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}}; -{% endif %} +{% for method in service.methods %}{% for parameter in method.parameters.all %}{% if not loop.first %}{% endif %}{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}}; {% endif %}{% endfor %}{% endfor %} class {{ service.name | caseUcfirst }} extends Service From 5e6e4ee342c31e20007524f901ef52bf78e1a276 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 4 Aug 2023 19:42:16 +0530 Subject: [PATCH 36/98] chore: revert changes --- src/SDK/Language/Dart.php | 4 ---- src/SDK/Language/DotNet.php | 3 --- src/SDK/Language/JS.php | 3 --- src/SDK/Language/Kotlin.php | 3 --- src/SDK/Language/PHP.php | 3 --- src/SDK/Language/Web.php | 4 ---- 6 files changed, 20 deletions(-) diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index bca1f3bbe..753d6259f 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -121,10 +121,6 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName'] . ' '; - } - switch ($parameter['type']) { case self::TYPE_INTEGER: return 'int'; diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 84c92e7ad..ef8e19aad 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -151,9 +151,6 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName']; - } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index d3d51b133..a4a0ba64c 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -124,9 +124,6 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName']; - } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index ac0ca0ebd..df2329e21 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -105,9 +105,6 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName']; - } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 750da6cdd..c3f505e01 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -227,9 +227,6 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName'] . ' '; - } switch ($parameter['type']) { case self::TYPE_STRING: diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 08d187a73..d6838af6c 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -179,10 +179,6 @@ public function getParamExample(array $param): string public function getTypeName(array $parameter, array $method = []): string { - if (isset($parameter['enumName'])) { - return $parameter['enumName']; - } - switch ($parameter['type']) { case self::TYPE_INTEGER: case self::TYPE_NUMBER: From f707669f631c5e3ef4c469fbed77a7bba7893c81 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 4 Aug 2023 19:46:23 +0530 Subject: [PATCH 37/98] chore: revert changes --- templates/php/src/Services/Service.php.twig | 2 -- 1 file changed, 2 deletions(-) diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index c6b58a367..3e110cffe 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -6,8 +6,6 @@ use {{ spec.title | caseUcfirst }}\{{spec.title | caseUcfirst}}Exception; use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\Service; use {{ spec.title | caseUcfirst }}\InputFile; -{% for method in service.methods %}{% for parameter in method.parameters.all %}{% if not loop.first %}{% endif %}{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}}; -{% endif %}{% endfor %}{% endfor %} class {{ service.name | caseUcfirst }} extends Service { From cfef3225e8f98e4c417764f7abfe91a489f661fe Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi <62933155+2002Bishwajeet@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:14:25 +0530 Subject: [PATCH 38/98] Update templates/dotnet/src/Appwrite/Enums/Enums.cs.twig Co-authored-by: Aditya Oberai --- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 12a73f004..6fc3aca9f 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -6,7 +6,7 @@ namespace {{ spec.title | caseUcfirst }}.Enums { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static readonly string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}" + public static string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; {% if not loop.last %},{% endif %} {% endfor %} } From 4dbd72cb5220c370a760dfd9a9c965f3455cc498 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi <62933155+2002Bishwajeet@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:14:34 +0530 Subject: [PATCH 39/98] Update templates/dotnet/src/Appwrite/Enums/Enums.cs.twig Co-authored-by: Aditya Oberai --- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 6fc3aca9f..9eb104dc6 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -7,7 +7,7 @@ namespace {{ spec.title | caseUcfirst }}.Enums {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} public static string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; - {% if not loop.last %},{% endif %} + {% if not loop.last %}{% endif %} {% endfor %} } } \ No newline at end of file From 2ff035cea1aaae26e30968e6731faa553b7158a8 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi <62933155+2002Bishwajeet@users.noreply.github.com> Date: Fri, 4 Aug 2023 20:22:51 +0530 Subject: [PATCH 40/98] chore: remove empty last loop --- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 9eb104dc6..2d04bb3a6 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -7,7 +7,6 @@ namespace {{ spec.title | caseUcfirst }}.Enums {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} public static string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; - {% if not loop.last %}{% endif %} {% endfor %} } -} \ No newline at end of file +} From f9da819284a086cdaa588abea8a3d29d14503755 Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Fri, 11 Aug 2023 23:34:38 +0530 Subject: [PATCH 41/98] fix enum addition when found in body --- src/Spec/Swagger2.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 4cad9f1eb..f0025f246 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -259,6 +259,12 @@ public function getMethods($service) $value['default'] = (empty($value['default'])) ? new stdClass() : $value['default']; } + if (isset($value['enum'])) { + $param['enumValues'] = $value['enum']; + $param['enumName'] = $value['x-enum-name']; + $param['enumKeys'] = $value['x-enum-keys']; + } + $param['default'] = (is_array($value['default']) || $value['default'] instanceof stdClass) ? json_encode($value['default']) : $value['default']; $output['parameters']['body'][] = $param; From 453ffdb3277bf6ce014e57e58dc8f90044e0c3ff Mon Sep 17 00:00:00 2001 From: Bishwajeet Parhi Date: Mon, 14 Aug 2023 17:00:46 +0530 Subject: [PATCH 42/98] fix: duplicate enums --- src/Spec/Swagger2.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index f0025f246..db436ac93 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -245,14 +245,15 @@ public function getMethods($service) $bodyRequired = $parameter['schema']['required'] ?? []; foreach ($bodyProperties as $key => $value) { - $param['name'] = $key; - $param['type'] = $value['type'] ?? null; - $param['description'] = $value['description'] ?? ''; - $param['required'] = (in_array($key, $bodyRequired)); - $param['example'] = $value['x-example'] ?? null; - $param['isUploadID'] = $value['x-upload-id'] ?? false; - $param['nullable'] = $value['x-nullable'] ?? false; - $param['array'] = [ + $temp = $param; + $temp['name'] = $key; + $temp['type'] = $value['type'] ?? null; + $temp['description'] = $value['description'] ?? ''; + $temp['required'] = (in_array($key, $bodyRequired)); + $temp['example'] = $value['x-example'] ?? null; + $temp['isUploadID'] = $value['x-upload-id'] ?? false; + $temp['nullable'] = $value['x-nullable'] ?? false; + $temp['array'] = [ 'type' => $value['items']['type'] ?? '', ]; if ($value['type'] === 'object' && is_array($value['default'])) { @@ -260,15 +261,15 @@ public function getMethods($service) } if (isset($value['enum'])) { - $param['enumValues'] = $value['enum']; - $param['enumName'] = $value['x-enum-name']; - $param['enumKeys'] = $value['x-enum-keys']; + $temp['enumValues'] = $value['enum']; + $temp['enumName'] = $value['x-enum-name']; + $temp['enumKeys'] = $value['x-enum-keys']; } - $param['default'] = (is_array($value['default']) || $value['default'] instanceof stdClass) ? json_encode($value['default']) : $value['default']; + $temp['default'] = (is_array($value['default']) || $value['default'] instanceof stdClass) ? json_encode($value['default']) : $value['default']; - $output['parameters']['body'][] = $param; - $output['parameters']['all'][] = $param; + $output['parameters']['body'][] = $temp; + $output['parameters']['all'][] = $temp; } continue 2; @@ -371,6 +372,6 @@ public function getEnumNames(): array } } } - return $list; + return \array_values(\array_unique($list)); } } From c7613e16d6974dd9ffaa5ddadea1284a1e35cb77 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:22:08 -0400 Subject: [PATCH 43/98] Add ruby enum template --- src/SDK/Language/Ruby.php | 5 +++++ templates/ruby/lib/container/enums/enum.rb.twig | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 templates/ruby/lib/container/enums/enum.rb.twig diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index eb50551b0..f94b4a9a3 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -182,6 +182,11 @@ public function getFiles(): array 'destination' => '/lib/{{ spec.title | caseDash }}/models/{{ definition.name | caseSnake }}.rb', 'template' => 'ruby/lib/container/models/model.rb.twig', ], + [ + 'scope' => 'enum', + 'destination' => 'lib/{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.rb', + 'template' => 'ruby/lib/container/enums/enum.rb.twig', + ], ]; } diff --git a/templates/ruby/lib/container/enums/enum.rb.twig b/templates/ruby/lib/container/enums/enum.rb.twig new file mode 100644 index 000000000..14f793ca7 --- /dev/null +++ b/templates/ruby/lib/container/enums/enum.rb.twig @@ -0,0 +1,8 @@ +module {{ spec.title | caseUcfirst }} + module {{ enum.name | caseUcfirst | overrideIdentifier }} +{% for value in enum.enum %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = '{{ value }}' +{% endfor %} + end +end \ No newline at end of file From 5ea227a04dfe8aefa911912c553dfba7001cbad1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:22:24 -0400 Subject: [PATCH 44/98] Fix Kotlin enums --- .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 4 ++-- .../kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 71959357e..8ca276ed2 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -2,8 +2,8 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':''})}}("{{value}}"){% if not loop.last %}, +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': ''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index 1322953de..9b83aa8e4 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': ''})}}("{{value}}"){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': ''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} From 996b1d10703df87ec7365b65277d766da3fc85e1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:22:32 -0400 Subject: [PATCH 45/98] Fix dotnet enums --- templates/dotnet/src/Appwrite/Enums/Enums.cs.twig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 2d04bb3a6..4d1d1c7a8 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -4,9 +4,9 @@ namespace {{ spec.title | caseUcfirst }}.Enums { public static class {{ enum.name | caseUcfirst | overrideIdentifier }} { - {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; - {% endfor %} +{% for value in enum.enum %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public const string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; +{% endfor %} } } From 9111b869cdb774fbc38a0ff52f776e0449da22c3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:22:44 -0400 Subject: [PATCH 46/98] Fix web enums --- templates/node/lib/enums/enum.js.twig | 10 +++++----- templates/web/src/enums/enum.ts.twig | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/node/lib/enums/enum.js.twig b/templates/node/lib/enums/enum.js.twig index e9afe841d..8d7fd4652 100644 --- a/templates/node/lib/enums/enum.js.twig +++ b/templates/node/lib/enums/enum.js.twig @@ -1,9 +1,9 @@ const {{ enum.name | caseUcfirst | overrideIdentifier }} = { - {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseLower | replace({'-': '',' ': ''})}}: '{{value}}' {% if not loop.last %}, - {% endif %} - {% endfor %} +{% for value in enum.enum %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseCamel | replace({'-': '',' ': ''})}}: '{{value}}' {% if not loop.last %},{% endif %} + +{% endfor %} } module.exports = {{ enum.name | caseUcfirst | overrideIdentifier }}; \ No newline at end of file diff --git a/templates/web/src/enums/enum.ts.twig b/templates/web/src/enums/enum.ts.twig index d9366b495..bd20d2cb5 100644 --- a/templates/web/src/enums/enum.ts.twig +++ b/templates/web/src/enums/enum.ts.twig @@ -1,6 +1,6 @@ export enum {{ enum.name | caseUcfirst }} { - {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} +{% for value in enum.enum %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} {{ key | caseUcfirst | replace({'-': ''})}} = '{{ value }}', - {% endfor %} +{% endfor %} } \ No newline at end of file From 8544575d7d1878d8eed49cf51781e461a76a5baa Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:22:53 -0400 Subject: [PATCH 47/98] Fix PHP enums --- templates/php/src/Enums/Enum.php.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index 66c0afd79..fc14169e8 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -5,7 +5,7 @@ namespace {{ spec.title | caseUcfirst }}\Enums; class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const {{ key | caseUpper | replace({'-': '',' ': '_'})}} = '{{value}}'; +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + public const {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = '{{value}}'; {% endfor %} -} +} \ No newline at end of file From 55164a01ebc751b15e271ff684df427dfbdb947d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:23:03 -0400 Subject: [PATCH 48/98] Fix python enums --- templates/python/package/enums/enum.py.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 0358d0549..05b87bd5d 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -2,6 +2,6 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': ''})}} = "{{ value }}" +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file From c5e70bf46dfa70528b0f4fad94d28a4ce86b2fc0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:23:17 -0400 Subject: [PATCH 49/98] Fix swift enums --- templates/swift/Package.swift.twig | 4 ++++ templates/swift/Sources/Enums/Enum.swift.twig | 1 + 2 files changed, 5 insertions(+) diff --git a/templates/swift/Package.swift.twig b/templates/swift/Package.swift.twig index 0204ec6f2..775723512 100644 --- a/templates/swift/Package.swift.twig +++ b/templates/swift/Package.swift.twig @@ -27,6 +27,7 @@ let package = Package( .product(name: "AsyncHTTPClient", package: "async-http-client"), .product(name: "NIOWebSocket", package: "swift-nio"), "{{spec.title | caseUcfirst}}Models", + "{{spec.title | caseUcfirst}}Enums", "JSONCodable" ] ), @@ -36,6 +37,9 @@ let package = Package( "JSONCodable" ] ), + .target( + name: "{{spec.title | caseUcfirst}}Enums" + ), .target( name: "JSONCodable" ), diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index 341164ab4..8f8906dfb 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -3,3 +3,4 @@ enum {{ enum.name | caseUcfirst | overrideIdentifier }} : String { {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} case {{ key | caseCamel | replace({'-': ''})}} = '{{ value }}' {% endfor %} +} From 98870d04a418a0bda581a2ec4960d492e5fce526 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:29:08 -0400 Subject: [PATCH 50/98] Fix enums --- templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- templates/php/src/Enums/Enum.php.twig | 2 +- templates/ruby/lib/container/enums/enum.rb.twig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index 9b83aa8e4..fbfe94292 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': ''})}}("{{value}}"){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index fc14169e8..6d35b3c74 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,6 +6,6 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = '{{value}}'; + public const {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}} = '{{value}}'; {% endfor %} } \ No newline at end of file diff --git a/templates/ruby/lib/container/enums/enum.rb.twig b/templates/ruby/lib/container/enums/enum.rb.twig index 14f793ca7..7c6dcce34 100644 --- a/templates/ruby/lib/container/enums/enum.rb.twig +++ b/templates/ruby/lib/container/enums/enum.rb.twig @@ -2,7 +2,7 @@ module {{ spec.title | caseUcfirst }} module {{ enum.name | caseUcfirst | overrideIdentifier }} {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = '{{ value }}' + {{ key | caseUpper | replace({'-': '', ' ':'_', '(': '', ')': '', '.': ''})}} = '{{ value }}' {% endfor %} end end \ No newline at end of file From f2f97fff1f3b161993dc12c98b5e60d5115c2e05 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:38:51 -0400 Subject: [PATCH 51/98] Fix enums --- .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 2 +- templates/python/package/enums/enum.py.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 8ca276ed2..7e5e2b941 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': ''})}}("{{value}}"){% if not loop.last %}, + {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}}("{{value}}"){% if not loop.last %}, {% endif %} {% endfor %} diff --git a/templates/python/package/enums/enum.py.twig b/templates/python/package/enums/enum.py.twig index 05b87bd5d..e8883e914 100644 --- a/templates/python/package/enums/enum.py.twig +++ b/templates/python/package/enums/enum.py.twig @@ -3,5 +3,5 @@ from enum import Enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(Enum): {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ': '_', '(': '', ')': ''})}} = "{{ value }}" + {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}} = "{{ value }}" {% endfor %} \ No newline at end of file From 9912b273582359f7ffed02002e9261ff53af9976 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 15:47:57 -0400 Subject: [PATCH 52/98] Fix tests --- templates/dotnet/src/Appwrite/Client.cs.twig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/dotnet/src/Appwrite/Client.cs.twig b/templates/dotnet/src/Appwrite/Client.cs.twig index 3692008d3..277d6ecd4 100644 --- a/templates/dotnet/src/Appwrite/Client.cs.twig +++ b/templates/dotnet/src/Appwrite/Client.cs.twig @@ -326,7 +326,7 @@ namespace {{ spec.title | caseUcfirst }} parameters = new Dictionary() ); var chunksUploaded = (long)current["chunksUploaded"]; - offset = Math.Min(chunksUploaded * ChunkSize, size); + offset = chunksUploaded * ChunkSize; } while (offset < size) @@ -342,7 +342,7 @@ namespace {{ spec.title | caseUcfirst }} case "bytes": buffer = ((byte[])input.Data) .Skip((int)offset) - .Take((int)Math.Min(size - offset, ChunkSize)) + .Take((int)Math.Min(size - offset, ChunkSize - 1)) .ToArray(); break; } @@ -354,7 +354,7 @@ namespace {{ spec.title | caseUcfirst }} parameters[paramName] = content; headers["Content-Range"] = - $"bytes {offset}-{Math.Min(offset + ChunkSize - 1, size)}/{size}"; + $"bytes {offset}-{Math.Min(offset + ChunkSize - 1, size - 1)}/{size}"; result = await Call>( method: "POST", From 10b5323006ba37b558b2911e9edfd2de554ad7d1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 21:50:29 -0400 Subject: [PATCH 53/98] Fix enums --- src/SDK/Language/Dart.php | 3 ++ src/SDK/Language/DotNet.php | 3 ++ src/SDK/Language/Kotlin.php | 3 ++ src/SDK/Language/PHP.php | 5 +++- src/SDK/Language/Web.php | 3 ++ src/SDK/SDK.php | 6 ++++ .../main/java/io/appwrite/enums/Enum.kt.twig | 5 ++-- .../appwrite/services/ServiceTemplate.kt.twig | 3 +- templates/dart/lib/package.dart.twig | 2 +- templates/deno/mod.ts.twig | 4 +-- templates/deno/src/services/service.ts.twig | 9 ++++++ templates/dotnet/base/params.twig | 2 +- .../dotnet/src/Appwrite/Enums/Enums.cs.twig | 16 +++++++++-- .../Appwrite/Services/ServiceTemplate.cs.twig | 1 + templates/flutter/lib/package.dart.twig | 2 +- .../kotlin/io/appwrite/enums/Enum.kt.twig | 7 +++-- .../appwrite/services/ServiceTemplate.kt.twig | 3 +- templates/node/index.js.twig | 4 +-- templates/php/src/Enums/Enum.php.twig | 28 +++++++++++++++++-- templates/php/src/Services/Service.php.twig | 13 +++++++-- templates/swift/Sources/Enums/Enum.swift.twig | 4 +-- templates/swift/base/params.twig | 2 +- templates/web/src/index.ts.twig | 2 +- templates/web/src/services/template.ts.twig | 9 ++++++ 24 files changed, 114 insertions(+), 25 deletions(-) diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 753d6259f..2d79980c2 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -121,6 +121,9 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } switch ($parameter['type']) { case self::TYPE_INTEGER: return 'int'; diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index ef8e19aad..84c92e7ad 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -151,6 +151,9 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index df2329e21..ac0ca0ebd 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -105,6 +105,9 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index c3f505e01..6b1078ac3 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -227,6 +227,9 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } switch ($parameter['type']) { case self::TYPE_STRING: @@ -248,7 +251,7 @@ public function getTypeName(array $parameter): string break; } - return $type . ' '; + return $type; } /** diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index d6838af6c..a45471885 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -179,6 +179,9 @@ public function getParamExample(array $param): string public function getTypeName(array $parameter, array $method = []): string { + if (isset($parameter['enumName'])) { + return $parameter['enumName']; + } switch ($parameter['type']) { case self::TYPE_INTEGER: case self::TYPE_NUMBER: diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 639fa1247..f579242de 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -191,6 +191,12 @@ public function __construct(Language $language, Spec $spec) } return $value; })); + $this->twig->addFilter(new TwigFilter('strip', function($value) { + $value = \str_replace(['-',' ',], '_', $value); + $value = \preg_replace('/[^A-Za-z0-9_]/', '', $value); + + return $value; + })); } /** diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 7e5e2b941..c4adaa651 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,8 +3,9 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}}("{{value}}"){% if not loop.last %}, -{% endif %} + {{ key | caseUpper | strip }}("{{value}}"){% if not loop.last %},{%else %};{% endif %} + {% endfor %} + override fun toString() = value } \ No newline at end of file diff --git a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig index f2a331c4e..fdce2e275 100644 --- a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig @@ -2,6 +2,7 @@ package {{ sdk.namespace | caseDot }}.services import android.net.Uri import {{ sdk.namespace | caseDot }}.Client +import {{ sdk.namespace | caseDot }}.enums.* import {{ sdk.namespace | caseDot }}.models.* import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception import {{ sdk.namespace | caseDot }}.extensions.classOf @@ -55,7 +56,7 @@ class {{ service.name | caseUcfirst }} : Service { ){% if method.type != "webAuth" %}: {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}{% endif %} { val path = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}) + .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumName is not null %}.value{% endif %}) {%~ endfor %} val params = mutableMapOf( diff --git a/templates/dart/lib/package.dart.twig b/templates/dart/lib/package.dart.twig index 0b0942d8e..ad4e6d43d 100644 --- a/templates/dart/lib/package.dart.twig +++ b/templates/dart/lib/package.dart.twig @@ -27,6 +27,6 @@ part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; {% endfor %} -{% for enum in enums %} +{% for enum in spec.enums %} part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} diff --git a/templates/deno/mod.ts.twig b/templates/deno/mod.ts.twig index 4d6e5bab7..fea529ed2 100644 --- a/templates/deno/mod.ts.twig +++ b/templates/deno/mod.ts.twig @@ -8,7 +8,7 @@ import { {{spec.title | caseUcfirst}}Exception } from "./src/exception.ts"; {% for service in spec.services %} import { {{service.name | caseUcfirst}} } from "./src/services/{{service.name | caseDash}}.ts"; {% endfor %} -{% for enum in enums %} +{% for enum in spec.enums %} import { {{enum | caseUcfirst}} } from "./src/enums/{{enum | caseDash}}.ts"; {% endfor %} @@ -23,7 +23,7 @@ export { {% for service in spec.services %} {{service.name | caseUcfirst}}, {% endfor %} -{% for enum in enums %} +{% for enum in spec.enums %} {{enum | caseUcfirst}}, {% endfor %} }; diff --git a/templates/deno/src/services/service.ts.twig b/templates/deno/src/services/service.ts.twig index 8fdd11841..d9b5c8a73 100644 --- a/templates/deno/src/services/service.ts.twig +++ b/templates/deno/src/services/service.ts.twig @@ -31,6 +31,15 @@ import { Payload, Client } from '../client.ts'; import { InputFile } from '../inputFile.ts'; import { AppwriteException } from '../exception.ts'; import type { Models } from '../models.d.ts'; +{% set added = [] %} +{% for method in service.methods %} +{% for parameter in method.parameters.all %} +{% if parameter.enumName is not null and parameter.enumName not in added %} +import {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; +{% set added = added|merge([parameter.enumName]) %} +{% endif %} +{% endfor %} +{% endfor %} export type UploadProgress = { $id: string; diff --git a/templates/dotnet/base/params.twig b/templates/dotnet/base/params.twig index 1ce2c6fd2..851761f46 100644 --- a/templates/dotnet/base/params.twig +++ b/templates/dotnet/base/params.twig @@ -1,6 +1,6 @@ {% import 'dotnet/base/utils.twig' as utils %} {%~ for parameter in method.parameters.path %} - .Replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel | escapeKeyword }}){% if loop.last %};{% endif %} + .Replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel | escapeKeyword }}{% if parameter.enumName is not null %}.Value{% endif %}){% if loop.last %};{% endif %} {%~ endfor %} diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 4d1d1c7a8..5ce71ab47 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -2,11 +2,23 @@ using System; namespace {{ spec.title | caseUcfirst }}.Enums { - public static class {{ enum.name | caseUcfirst | overrideIdentifier }} + public class {{ enum.name | caseUcfirst | overrideIdentifier }} { + public string Value { get; private set; } + + public {{ enum.name | caseUcfirst | overrideIdentifier }}(string value) + { + Value = value; + } + {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const string {{ key | caseUcfirst | replace({'-': ''}) }} => "{{ value }}"; + public static {{ enum.name | caseUcfirst | overrideIdentifier }} {{ key | caseUcfirst | strip }} => new {{ enum.name | caseUcfirst | overrideIdentifier }}("{{ value }}"); {% endfor %} + + public override string ToString() + { + return Value; + } } } diff --git a/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig b/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig index a7711ec93..67f501c0d 100644 --- a/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig +++ b/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using {{ spec.title | caseUcfirst }}.Models; +using {{ spec.title | caseUcfirst }}.Enums; namespace {{ spec.title | caseUcfirst }}.Services { diff --git a/templates/flutter/lib/package.dart.twig b/templates/flutter/lib/package.dart.twig index ca6dc09c8..6b1d38848 100644 --- a/templates/flutter/lib/package.dart.twig +++ b/templates/flutter/lib/package.dart.twig @@ -29,6 +29,6 @@ part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; {% endfor %} -{% for enum in enums %} +{% for enum in spec.enums %} part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index fbfe94292..a1af9caea 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -2,9 +2,10 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}}("{{value}}"){% if not loop.last %}, -{% endif %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | strip }}("{{value}}"){% if not loop.last %},{% else %};{% endif %} + {% endfor %} + override fun toString() = value } \ No newline at end of file diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig index 682752960..d0ee52be1 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig @@ -2,6 +2,7 @@ package {{ sdk.namespace | caseDot }}.services import {{ sdk.namespace | caseDot }}.Client import {{ sdk.namespace | caseDot }}.models.* +import {{ sdk.namespace | caseDot }}.enums.* import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception import {{ sdk.namespace | caseDot }}.extensions.classOf import okhttp3.Cookie @@ -51,7 +52,7 @@ class {{ service.name | caseUcfirst }} : Service { ): {{ method | returnType(spec, sdk.namespace | caseDot) | raw }} { val path = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}) + .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumName is not null %}.value{% endif %}) {%~ endfor %} val params = mutableMapOf( diff --git a/templates/node/index.js.twig b/templates/node/index.js.twig index ddd31be72..7953c18f7 100644 --- a/templates/node/index.js.twig +++ b/templates/node/index.js.twig @@ -8,7 +8,7 @@ const {{spec.title | caseUcfirst}}Exception = require('./lib/exception.js'); {% for service in spec.services %} const {{service.name | caseUcfirst}} = require('./lib/services/{{service.name | caseDash}}.js'); {% endfor %} -{% for enum in enums %} +{% for enum in spec.enums %} const {{enum | caseUcfirst}} = require("./lib/enums/{{enum | caseDash}}.js"); {% endfor %} @@ -22,7 +22,7 @@ module.exports = { {{spec.title | caseUcfirst}}Exception, {% for service in spec.services %} {{service.name | caseUcfirst}}, -{% endfor %}{% for enum in enums %} +{% endfor %}{% for enum in spec.enums %} {{ enum | caseUcfirst }}, {% endfor %} }; diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index 6d35b3c74..fa3735aa0 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -2,10 +2,34 @@ namespace {{ spec.title | caseUcfirst }}\Enums; -class {{ enum.name | caseUcfirst | overrideIdentifier }} +class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { + private string $value; + + public function __construct(string $value) + { + $this->value = $value; + +{% for value in enum.enum %} +{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + if (!isset(self::${{ key | caseUpper | strip }})) { + self::${{ key | caseUpper | strip }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); + } +{% endfor %} + } + + public function __toString(): string + { + return $this->value; + } + + public function jsonSerialize(): string + { + return $this->value; + } + {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public const {{ key | caseUpper | replace({'-': '',' ':'_', '(': '', ')': '', '.': ''})}} = '{{value}}'; + public static {{ enum.name | caseUcfirst | overrideIdentifier }} ${{ key | caseUpper | strip }}; {% endfor %} } \ No newline at end of file diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index 3e110cffe..4b2717df9 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -6,6 +6,15 @@ use {{ spec.title | caseUcfirst }}\{{spec.title | caseUcfirst}}Exception; use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\Service; use {{ spec.title | caseUcfirst }}\InputFile; +{% set added = [] %} +{% for method in service.methods %} +{% for parameter in method.parameters.all %} +{% if parameter.enumName is not null and parameter.enumName not in added %} +use {{ spec.title | caseUcfirst }}\Enums\{{ parameter.enumName | caseUcfirst }}; +{% set added = added|merge([parameter.enumName]) %} +{% endif %} +{% endfor %} +{% endfor %} class {{ service.name | caseUcfirst }} extends Service { @@ -23,13 +32,13 @@ class {{ service.name | caseUcfirst }} extends Service * {% endif %} {% for parameter in method.parameters.all %} - * @param {{ parameter | typeName }}${{ parameter.name | caseCamel | escapeKeyword }} + * @param {{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }} {% endfor %} * @throws {{spec.title | caseUcfirst}}Exception * @return {{ method | getReturn }} */ - public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }} + public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }} { $path = str_replace([{% for parameter in method.parameters.path %}'{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'{% if not loop.last %}, {% endif %}{% endfor %}], [{% for parameter in method.parameters.path %}${{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last %}, {% endif %}{% endfor %}], '{{ method.path }}'); diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index 8f8906dfb..3da2ebc5d 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -1,6 +1,6 @@ -enum {{ enum.name | caseUcfirst | overrideIdentifier }} : String { +public enum {{ enum.name | caseUcfirst | overrideIdentifier }} : String { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - case {{ key | caseCamel | replace({'-': ''})}} = '{{ value }}' + case {{ key | caseCamel | replace({'-': ''})}} = "{{ value }}" {% endfor %} } diff --git a/templates/swift/base/params.twig b/templates/swift/base/params.twig index 4fe11e5aa..d2ca15011 100644 --- a/templates/swift/base/params.twig +++ b/templates/swift/base/params.twig @@ -1,6 +1,6 @@ let path: String = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeKeyword }}) + .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeKeyword }}{% if parameter.enumName is not null %}.rawValue{% endif %}) {%~ endfor %} {%~ if method.parameters.query | merge(method.parameters.body) | length <= 0 %} diff --git a/templates/web/src/index.ts.twig b/templates/web/src/index.ts.twig index dcee4ebc4..a4b9fef71 100644 --- a/templates/web/src/index.ts.twig +++ b/templates/web/src/index.ts.twig @@ -7,6 +7,6 @@ export type { QueryTypes, QueryTypesList } from './query'; export { Permission } from './permission'; export { Role } from './role'; export { ID } from './id'; -{% for enum in enums %} +{% for enum in spec.enums %} export { {{ enum | caseUcfirst }} } from './enums/{{enum | caseDash}}'; {% endfor %} \ No newline at end of file diff --git a/templates/web/src/services/template.ts.twig b/templates/web/src/services/template.ts.twig index 40b33684c..1ec8a5682 100644 --- a/templates/web/src/services/template.ts.twig +++ b/templates/web/src/services/template.ts.twig @@ -2,6 +2,15 @@ import { Service } from '../service'; import { {{ spec.title | caseUcfirst}}Exception, Client } from '../client'; import type { Models } from '../models'; import type { UploadProgress, Payload } from '../client'; +{% set added = [] %} +{% for method in service.methods %} +{% for parameter in method.parameters.all %} +{% if parameter.enumName is not null and parameter.enumName not in added %} +import {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; +{% set added = added|merge([parameter.enumName]) %} +{% endif %} +{% endfor %} +{% endfor %} export class {{ service.name | caseUcfirst }} extends Service { From 2f5d5f5c0b471d6b84466ab8405cd35d2a63100c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 15 Aug 2023 22:26:48 -0400 Subject: [PATCH 54/98] Fix lint --- src/SDK/SDK.php | 4 ++-- templates/deno/src/services/service.ts.twig | 2 +- templates/web/src/services/template.ts.twig | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index f579242de..203d06cdf 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -191,7 +191,7 @@ public function __construct(Language $language, Spec $spec) } return $value; })); - $this->twig->addFilter(new TwigFilter('strip', function($value) { + $this->twig->addFilter(new TwigFilter('strip', function ($value) { $value = \str_replace(['-',' ',], '_', $value); $value = \preg_replace('/[^A-Za-z0-9_]/', '', $value); @@ -551,6 +551,7 @@ public function generate(string $target): void 'contactURL' => $this->spec->getContactURL(), 'contactEmail' => $this->spec->getContactEmail(), 'services' => $this->spec->getServices(), + 'enums' => $this->spec->getEnumNames(), 'definitions' => $this->spec->getDefinitions(), 'global' => [ 'headers' => $this->spec->getGlobalHeaders(), @@ -562,7 +563,6 @@ public function generate(string $target): void 'params' => $this->language->getParams(), ], 'sdk' => $this->getParams(), - 'enums' => $this->spec->getEnumNames(), ]; foreach ($this->language->getFiles() as $file) { diff --git a/templates/deno/src/services/service.ts.twig b/templates/deno/src/services/service.ts.twig index d9b5c8a73..b5b102c2d 100644 --- a/templates/deno/src/services/service.ts.twig +++ b/templates/deno/src/services/service.ts.twig @@ -35,7 +35,7 @@ import type { Models } from '../models.d.ts'; {% for method in service.methods %} {% for parameter in method.parameters.all %} {% if parameter.enumName is not null and parameter.enumName not in added %} -import {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; +import type {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; {% set added = added|merge([parameter.enumName]) %} {% endif %} {% endfor %} diff --git a/templates/web/src/services/template.ts.twig b/templates/web/src/services/template.ts.twig index 1ec8a5682..793510cde 100644 --- a/templates/web/src/services/template.ts.twig +++ b/templates/web/src/services/template.ts.twig @@ -6,7 +6,7 @@ import type { UploadProgress, Payload } from '../client'; {% for method in service.methods %} {% for parameter in method.parameters.all %} {% if parameter.enumName is not null and parameter.enumName not in added %} -import {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; +import type {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; {% set added = added|merge([parameter.enumName]) %} {% endif %} {% endfor %} From b0bafd69f2be1d6420c4f6d8f61989d64372d95c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 16 Aug 2023 11:32:38 -0400 Subject: [PATCH 55/98] Fix tests --- .../java/io/appwrite/services/ServiceTemplate.kt.twig | 6 +++++- .../dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig | 4 ++++ .../kotlin/io/appwrite/services/ServiceTemplate.kt.twig | 4 ++++ templates/swift/Package.swift.twig | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig index fdce2e275..338dda9ae 100644 --- a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig @@ -2,8 +2,12 @@ package {{ sdk.namespace | caseDot }}.services import android.net.Uri import {{ sdk.namespace | caseDot }}.Client -import {{ sdk.namespace | caseDot }}.enums.* +{% if spec.definitions is not empty %} import {{ sdk.namespace | caseDot }}.models.* +{% endif %} +{% if spec.enums is not empty %} +import {{ sdk.namespace | caseDot }}.enums.* +{% endif %} import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception import {{ sdk.namespace | caseDot }}.extensions.classOf {% if service.features.webAuth %} diff --git a/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig b/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig index 67f501c0d..1543662bb 100644 --- a/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig +++ b/templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig @@ -4,8 +4,12 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +{% if spec.definitions is not empty %} using {{ spec.title | caseUcfirst }}.Models; +{% endif %} +{% if spec.enums is not empty %} using {{ spec.title | caseUcfirst }}.Enums; +{% endif %} namespace {{ spec.title | caseUcfirst }}.Services { diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig index d0ee52be1..ddaeac5ca 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig @@ -1,8 +1,12 @@ package {{ sdk.namespace | caseDot }}.services import {{ sdk.namespace | caseDot }}.Client +{% if spec.definitions is not empty %} import {{ sdk.namespace | caseDot }}.models.* +{% endif %} +{% if spec.enums is not empty %} import {{ sdk.namespace | caseDot }}.enums.* +{% endif %} import {{ sdk.namespace | caseDot }}.exceptions.{{ spec.title | caseUcfirst }}Exception import {{ sdk.namespace | caseDot }}.extensions.classOf import okhttp3.Cookie diff --git a/templates/swift/Package.swift.twig b/templates/swift/Package.swift.twig index 775723512..d5ee138ec 100644 --- a/templates/swift/Package.swift.twig +++ b/templates/swift/Package.swift.twig @@ -26,20 +26,28 @@ let package = Package( dependencies: [ .product(name: "AsyncHTTPClient", package: "async-http-client"), .product(name: "NIOWebSocket", package: "swift-nio"), + {%~ if spec.definitions is not empty %} "{{spec.title | caseUcfirst}}Models", + {%~ endif %} + {%~ if spec.enums is not empty %} "{{spec.title | caseUcfirst}}Enums", + {%~ endif %} "JSONCodable" ] ), + {%~ if spec.definitions is not empty %} .target( name: "{{spec.title | caseUcfirst}}Models", dependencies: [ "JSONCodable" ] ), + {%~ endif %} + {%~ if spec.enums is not empty %} .target( name: "{{spec.title | caseUcfirst}}Enums" ), + {%~ endif %} .target( name: "JSONCodable" ), From 459e3d371d0b4bcb979c57ac87f495179b849513 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 7 Sep 2023 21:09:03 -0400 Subject: [PATCH 56/98] Add enum tests --- tests/Android11Java11Test.php | 5 ++-- tests/Android11Java8Test.php | 5 ++-- tests/Android12Java11Test.php | 5 ++-- tests/Android12Java8Test.php | 5 ++-- tests/Android5Java11Test.php | 5 ++-- tests/Android5Java8Test.php | 5 ++-- tests/AppleSwift55Test.php | 5 ++-- tests/Base.php | 46 +++++++++++------------------- tests/CLINode14Test.php | 2 +- tests/CLINode16Test.php | 2 +- tests/DartBetaTest.php | 3 +- tests/DartStableTest.php | 3 +- tests/Deno1193Test.php | 3 +- tests/Deno1303Test.php | 3 +- tests/DotNet31Test.php | 34 ---------------------- tests/DotNet60Test.php | 5 ++-- tests/DotNet70Test.php | 5 ++-- tests/FlutterBetaTest.php | 5 ++-- tests/FlutterStableTest.php | 5 ++-- tests/Go112Test.php | 3 +- tests/Go118Test.php | 3 +- tests/KotlinJava11Test.php | 5 ++-- tests/KotlinJava17Test.php | 5 ++-- tests/KotlinJava8Test.php | 5 ++-- tests/Node12Test.php | 3 +- tests/Node14Test.php | 3 +- tests/Node16Test.php | 3 +- tests/PHP74Test.php | 5 ++-- tests/PHP80Test.php | 5 ++-- tests/Python310Test.php | 5 ++-- tests/Python38Test.php | 5 ++-- tests/Python39Test.php | 5 ++-- tests/Ruby27Test.php | 5 ++-- tests/Ruby30Test.php | 5 ++-- tests/Ruby31Test.php | 5 ++-- tests/Swift55Test.php | 5 ++-- tests/WebChromiumTest.php | 6 ++-- tests/WebNodeTest.php | 3 +- tests/languages/android/Tests.kt | 6 ++++ tests/languages/apple/Tests.swift | 3 ++ tests/languages/dart/tests.dart | 24 ++++++++++++---- tests/languages/deno/tests.ts | 16 ++++++++++- tests/languages/dotnet/Tests.cs | 3 ++ tests/languages/flutter/tests.dart | 21 +++++++++++--- tests/languages/kotlin/Tests.kt | 6 ++++ tests/languages/node/test.js | 19 ++++++++++-- tests/languages/php/test.php | 4 +++ tests/languages/python/tests.py | 4 +++ tests/languages/ruby/tests.rb | 3 ++ tests/languages/swift/Tests.swift | 3 ++ tests/languages/web/index.html | 8 +++++- tests/languages/web/node.js | 7 ++++- 52 files changed, 202 insertions(+), 160 deletions(-) delete mode 100644 tests/DotNet31Test.php diff --git a/tests/Android11Java11Test.php b/tests/Android11Java11Test.php index 3985cd3f2..920674836 100644 --- a/tests/Android11Java11Test.php +++ b/tests/Android11Java11Test.php @@ -23,9 +23,8 @@ class Android11Java11Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Android11Java8Test.php b/tests/Android11Java8Test.php index a73b040ad..dccd0fd67 100644 --- a/tests/Android11Java8Test.php +++ b/tests/Android11Java8Test.php @@ -23,9 +23,8 @@ class Android11Java8Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Android12Java11Test.php b/tests/Android12Java11Test.php index 23eec2fbb..4eda88863 100644 --- a/tests/Android12Java11Test.php +++ b/tests/Android12Java11Test.php @@ -23,9 +23,8 @@ class Android12Java11Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Android12Java8Test.php b/tests/Android12Java8Test.php index 8718b25b4..20ae0f87a 100644 --- a/tests/Android12Java8Test.php +++ b/tests/Android12Java8Test.php @@ -23,9 +23,8 @@ class Android12Java8Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Android5Java11Test.php b/tests/Android5Java11Test.php index 0b29aff87..72248d594 100644 --- a/tests/Android5Java11Test.php +++ b/tests/Android5Java11Test.php @@ -23,9 +23,8 @@ class Android5Java11Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Android5Java8Test.php b/tests/Android5Java8Test.php index 6332f1040..393bf600f 100644 --- a/tests/Android5Java8Test.php +++ b/tests/Android5Java8Test.php @@ -23,9 +23,8 @@ class Android5Java8Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/AppleSwift55Test.php b/tests/AppleSwift55Test.php index b9b2e8842..3e0832ae2 100644 --- a/tests/AppleSwift55Test.php +++ b/tests/AppleSwift55Test.php @@ -22,9 +22,8 @@ class AppleSwift55Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::REALTIME_RESPONSES, ...Base::COOKIE_RESPONSES, diff --git a/tests/Base.php b/tests/Base.php index 5caa37d81..3cb4ea122 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -34,10 +34,9 @@ abstract class Base extends TestCase protected const GENERAL_RESPONSES = [ 'GET:/v1/mock/tests/general/redirect/done:passed', - 'POST:/v1/mock/tests/general/upload:passed', ]; - protected const EXTENDED_GENERAL_RESPONSES = [ + protected const DOWNLOAD_RESPONSES = [ 'GET:/v1/mock/tests/general/download:passed', ]; @@ -46,7 +45,14 @@ abstract class Base extends TestCase 'GET:/v1/mock/tests/general/get-cookie:passed', ]; - protected const LARGE_FILE_RESPONSES = [ + protected const ENUM_RESPONSES = [ + 'POST:/v1/mock/tests/general/enum:passed', + ]; + + protected const UPLOAD_RESPONSES = [ + 'POST:/v1/mock/tests/general/upload:passed', + 'POST:/v1/mock/tests/general/upload:passed', + 'POST:/v1/mock/tests/general/upload:passed', 'POST:/v1/mock/tests/general/upload:passed', ]; @@ -166,49 +172,31 @@ public function testHTTPSuccess(): void /** * Build SDK */ - foreach ($this->build as $key => $command) { - echo "Building phase #{$key} for {$this->language} package...\n"; - echo "Executing: {$command}\n"; - - $buildOutput = []; - - ob_end_clean(); + foreach ($this->build as $command) { echo "Build Executing: {$command}\n"; - ob_start(); - - exec($command, $buildOutput); - foreach ($buildOutput as $i => $row) { - echo "{$i}. {$row}\n"; - } + exec($command); } $output = []; - ob_end_clean(); echo "Env Executing: {$this->command}\n"; - ob_start(); exec($this->command, $output); - foreach ($output as $i => $row) { - echo "{$row}\n"; - } - $this->assertIsArray($output); do { - $removed = array_shift($output); + $removed = \array_shift($output); } while ($removed != 'Test Started' && sizeof($output) != 0); - $this->assertGreaterThanOrEqual(count($this->expectedOutput), count($output)); + echo \implode("\n", $output); - foreach ($this->expectedOutput as $i => $row) { - $this->assertEquals($output[$i], $row); - } + $this->assertEquals(\count($this->expectedOutput), \count($output)); + $this->assertEquals([], \array_diff($this->expectedOutput, $output)); } - private function rmdirRecursive($dir) + private function rmdirRecursive($dir): void { if (!\is_dir($dir)) { return; @@ -223,7 +211,7 @@ private function rmdirRecursive($dir) \unlink("$dir/$file"); } } - rmdir($dir); + \rmdir($dir); } public function getLanguage(): Language diff --git a/tests/CLINode14Test.php b/tests/CLINode14Test.php index 9986758d1..3d64f381a 100644 --- a/tests/CLINode14Test.php +++ b/tests/CLINode14Test.php @@ -25,7 +25,7 @@ class CLINode14Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - 'POST:/v1/mock/tests/general/upload:passed', //large file + ...Base::UPLOAD_RESPONSES, ]; public function getLanguage(): Language diff --git a/tests/CLINode16Test.php b/tests/CLINode16Test.php index c6ed8549c..db4fda0f3 100644 --- a/tests/CLINode16Test.php +++ b/tests/CLINode16Test.php @@ -25,7 +25,7 @@ class CLINode16Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - 'POST:/v1/mock/tests/general/upload:passed', //large file + ...Base::UPLOAD_RESPONSES, ]; public function getLanguage(): Language diff --git a/tests/DartBetaTest.php b/tests/DartBetaTest.php index f6dec74ee..90e5d053e 100644 --- a/tests/DartBetaTest.php +++ b/tests/DartBetaTest.php @@ -22,7 +22,8 @@ class DartBetaTest extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, ...Base::PERMISSION_HELPER_RESPONSES, diff --git a/tests/DartStableTest.php b/tests/DartStableTest.php index 1c586ab28..d3318fe80 100644 --- a/tests/DartStableTest.php +++ b/tests/DartStableTest.php @@ -22,7 +22,8 @@ class DartStableTest extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, ...Base::PERMISSION_HELPER_RESPONSES, diff --git a/tests/Deno1193Test.php b/tests/Deno1193Test.php index 29f5502ca..65404bdf2 100644 --- a/tests/Deno1193Test.php +++ b/tests/Deno1193Test.php @@ -19,7 +19,8 @@ class Deno1193Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, ...Base::PERMISSION_HELPER_RESPONSES, diff --git a/tests/Deno1303Test.php b/tests/Deno1303Test.php index fb09573b9..b102eeedf 100644 --- a/tests/Deno1303Test.php +++ b/tests/Deno1303Test.php @@ -19,7 +19,8 @@ class Deno1303Test extends Base ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, - ...Base::LARGE_FILE_RESPONSES, + ...Base::UPLOAD_RESPONSES, + ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ...Base::QUERY_HELPER_RESPONSES, ...Base::PERMISSION_HELPER_RESPONSES, diff --git a/tests/DotNet31Test.php b/tests/DotNet31Test.php deleted file mode 100644 index 9d0b6733a..000000000 --- a/tests/DotNet31Test.php +++ /dev/null @@ -1,34 +0,0 @@ -() { "string in array" }, InputFile.FromStream(info.OpenRead(), "large_file.mp4", "video/mp4")); TestContext.WriteLine(mock.Result); + mock = await general.Enum(MockType.First) + TestContext.WriteLine(mock.Result); + try { await general.Error400(); diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index b6fb89e3b..2338e7a18 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -79,13 +79,26 @@ void main() async { print(res['result']); var file = InputFile.fromPath(path: '../../resources/file.png', filename: 'file.png'); - response = await general.upload( - x: 'string', y: 123, z: ['string in array'], file: file); + response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); file = InputFile.fromPath(path: '../../resources/large_file.mp4', filename: 'large_file.mp4'); - response = await general.upload( - x: 'string', y: 123, z: ['string in array'], file: file); + response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); + print(response.result); + + var resource = new File.fromUri(Uri.parse('../../resources/file.png')); + var bytes = await resource.readAsBytes(); + file = InputFile.fromBytes(bytes: bytes, filename: 'file.png'); + response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); + print(response.result); + + resource = new File.fromUri(Uri.parse('../../resources/large_file.mp4')); + bytes = await resource.readAsBytes(); + file = InputFile.fromBytes(bytes: bytes, filename: 'large_file.mp4'); + response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); + print(response.result); + + response = await general.enum(MockType.FIRST); print(response.result); try { diff --git a/tests/languages/kotlin/Tests.kt b/tests/languages/kotlin/Tests.kt index 33b4ae06a..034c9325b 100644 --- a/tests/languages/kotlin/Tests.kt +++ b/tests/languages/kotlin/Tests.kt @@ -73,6 +73,9 @@ class ServiceTest { val result = general.redirect() writeToFile((result as Map)["result"] as String) + mock = general.enum(MockType.FIRST) + writeToFile(mock.result) + try { mock = general.upload("string", 123, listOf("string in array"), InputFile.fromPath("../../resources/file.png")) writeToFile(mock.result) @@ -100,6 +103,9 @@ class ServiceTest { writeToFile(ex.toString()) } + mock = general.enum(MockType.FIRST) + writeToFile(mock.result) + try { general.error400() } catch (e: AppwriteException) { diff --git a/tests/languages/node/test.js b/tests/languages/node/test.js index 259e7c0ea..c6da69fae 100644 --- a/tests/languages/node/test.js +++ b/tests/languages/node/test.js @@ -1,7 +1,7 @@ const appwrite = require('../../sdks/node/index'); const InputFile = require('../../sdks/node/lib/inputFile'); -const fs = require('fs'); +const fs = require('fs/promises'); async function start() { var response; @@ -10,9 +10,13 @@ async function start() { let Query = appwrite.Query; let Role = appwrite.Role; let ID = appwrite.ID; + let MockType = appwrite.MockType; // Init SDK - let client = new appwrite.Client(); + let client = new appwrite.Client() + .addHeader('Origin', 'http://localhost') + .setEndpoint('https://192.168.0.33/v1') + .setSelfSigned(); let foo = new appwrite.Foo(client); let bar = new appwrite.Bar(client); @@ -59,12 +63,23 @@ async function start() { response = await general.redirect(); console.log(response.result); + response = await general.enum(MockType.first); + console.log(response.result) + response = await general.upload('string', 123, ['string in array'], InputFile.fromPath(__dirname + '/../../resources/file.png', 'file.png')); console.log(response.result); response = await general.upload('string', 123, ['string in array'], InputFile.fromPath(__dirname + '/../../resources/large_file.mp4', 'large_file.mp4')); console.log(response.result); + let buffer = (await (await fs.open('./tests/resources/file.png')).read()).buffer; + response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'file.png')) + console.log(response.result) + + buffer = (await (await fs.open('./tests/resources/large_file.mp4')).read()).buffer; + response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'large_file.mp4')) + console.log(response.result) + try { response = await general.error400(); } catch(error) { diff --git a/tests/languages/php/test.php b/tests/languages/php/test.php index 4f74f4e60..e3cd83597 100644 --- a/tests/languages/php/test.php +++ b/tests/languages/php/test.php @@ -11,6 +11,7 @@ include __DIR__ . '/../../sdks/php/src/Appwrite/Services/Foo.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/Services/Bar.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/Services/General.php'; +include __DIR__ . '/../../sdks/php/src/Appwrite/Enums/MockType.php'; use Appwrite\AppwriteException; use Appwrite\Client; @@ -83,6 +84,9 @@ $response = $general->upload('string', 123, ['string in array'], InputFile::withPath(__DIR__ .'/../../resources/large_file.mp4')); echo "{$response['result']}\n"; +$response = $general->enum(MockType::FIRST); +echo "{$response['result']}\n"; + try { $response = $general->error400(); } catch (AppwriteException $e) { diff --git a/tests/languages/python/tests.py b/tests/languages/python/tests.py index 99f70c301..6a21c44cd 100644 --- a/tests/languages/python/tests.py +++ b/tests/languages/python/tests.py @@ -8,6 +8,7 @@ from appwrite.permission import Permission from appwrite.role import Role from appwrite.id import ID +from appwrite.mock_type import MockType import os.path @@ -75,6 +76,9 @@ response = general.upload('string', 123, ['string in array'], InputFile.from_bytes(data, 'large_file.mp4','video/mp4')) print(response['result']) +response = general.enum(MockType.FIRST) +print(response['result']) + try: response = general.error400() except AppwriteException as e: diff --git a/tests/languages/ruby/tests.rb b/tests/languages/ruby/tests.rb index 37fb0ef61..ce6d9ff4d 100644 --- a/tests/languages/ruby/tests.rb +++ b/tests/languages/ruby/tests.rb @@ -81,6 +81,9 @@ puts e end +response = general.enum(MockType::FIRST) +puts response.result + begin general.error400() rescue Exception => error diff --git a/tests/languages/swift/Tests.swift b/tests/languages/swift/Tests.swift index 948de3601..285918889 100644 --- a/tests/languages/swift/Tests.swift +++ b/tests/languages/swift/Tests.swift @@ -104,6 +104,9 @@ class Tests: XCTestCase { print(error.localizedDescription) } + mock = try await general.enum(.first) + print(mock.result) + do { try await general.error400() } catch { diff --git a/tests/languages/web/index.html b/tests/languages/web/index.html index 17387180f..2b24c296b 100644 --- a/tests/languages/web/index.html +++ b/tests/languages/web/index.html @@ -20,7 +20,7 @@ let response; let responseRealtime = 'Realtime failed!'; // Init SDK - const { Client, Foo, Bar, General, Query, Permission, Role, ID } = Appwrite; + const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = Appwrite; const client = new Client(); const foo = new Foo(client); const bar = new Bar(client); @@ -85,6 +85,12 @@ ); console.log(response.result); + console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip InputFile tests + console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip InputFile tests + + response = await general.enum(MockType.first); + console.log(response.result); + try { response = await general.empty(); } catch (error) { diff --git a/tests/languages/web/node.js b/tests/languages/web/node.js index 0ec235512..129c674a3 100644 --- a/tests/languages/web/node.js +++ b/tests/languages/web/node.js @@ -1,4 +1,4 @@ -const { Client, Foo, Bar, General, Query, Permission, Role, ID } = require('./dist/cjs/sdk.js'); +const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = require('./dist/cjs/sdk.js'); async function start() { let response; @@ -46,6 +46,11 @@ async function start() { console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip file upload test on Node.js console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip big file upload test on Node.js + console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip file upload test on Node.js + console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip big file upload test on Node.js + + response = await general.enum(MockType.first); + console.log(response.result); try { response = await general.empty(); From 951e5c9b8d45d91c42dc3cb5ed6e8ce9bd798040 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 7 Sep 2023 21:09:26 -0400 Subject: [PATCH 57/98] Update mock specs --- tests/resources/spec.json | 1274 +++++++++++++++++++++++++++++-------- 1 file changed, 1014 insertions(+), 260 deletions(-) diff --git a/tests/resources/spec.json b/tests/resources/spec.json index fae575b37..d8dccd7d8 100644 --- a/tests/resources/spec.json +++ b/tests/resources/spec.json @@ -1,93 +1,133 @@ { "swagger": "2.0", "info": { - "version": "0.15.3", + "version": "1.4.2", "title": "Appwrite", - "description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)", - "termsOfService": "https://appwrite.io/policy/terms", + "description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https:\/\/appwrite.io\/docs](https:\/\/appwrite.io\/docs)", + "termsOfService": "https:\/\/appwrite.io\/policy\/terms", "contact": { "name": "Appwrite Team", - "url": "https://appwrite.io/support", + "url": "https:\/\/appwrite.io\/support", "email": "team@appwrite.io" }, "license": { "name": "BSD-3-Clause", - "url": "https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE" + "url": "https:\/\/raw.githubusercontent.com\/appwrite\/appwrite\/master\/LICENSE" } }, - "host": "stage.appwrite.io", - "basePath": "/v1", - "schemes": ["https"], - "consumes": ["application/json", "multipart/form-data"], - "produces": ["application/json"], + "host": "sdk-generator-tests.appwrite.org", + "basePath": "\/v1", + "schemes": [ + "https" + ], + "consumes": [ + "application\/json", + "multipart\/form-data" + ], + "produces": [ + "application\/json" + ], "securityDefinitions": { "Project": { "type": "apiKey", "name": "X-Appwrite-Project", "description": "Your project ID", "in": "header", - "x-appwrite": { "demo": "5df5acd0d48c2" } + "x-appwrite": { + "demo": "5df5acd0d48c2" + } }, "Key": { "type": "apiKey", "name": "X-Appwrite-Key", "description": "Your secret API key", "in": "header", - "x-appwrite": { "demo": "919c2d18fb5d4...a2ae413da83346ad2" } + "x-appwrite": { + "demo": "919c2d18fb5d4...a2ae413da83346ad2" + } }, "JWT": { "type": "apiKey", "name": "X-Appwrite-JWT", "description": "Your secret JSON Web Token", "in": "header", - "x-appwrite": { "demo": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ..." } + "x-appwrite": { + "demo": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ..." + } }, "Locale": { "type": "apiKey", "name": "X-Appwrite-Locale", "description": "", "in": "header", - "x-appwrite": { "demo": "en" } + "x-appwrite": { + "demo": "en" + } }, "Mode": { "type": "apiKey", "name": "X-Appwrite-Mode", "description": "", "in": "header", - "x-appwrite": { "demo": "" } + "x-appwrite": { + "demo": "" + } } }, "paths": { - "/mock/tests/bar": { + "\/mock\/tests\/bar": { "get": { "summary": "Get Bar", "operationId": "barGet", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["bar"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "bar" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "get", - "weight": 232, + "weight": 270, "cookies": false, "type": "", - "demo": "bar/get.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a get request.", + "demo": "bar\/get.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a get request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "required", @@ -111,7 +151,9 @@ "required": true, "type": "array", "collectionFormat": "multi", - "items": { "type": "string" }, + "items": { + "type": "string" + }, "in": "query" } ] @@ -119,32 +161,55 @@ "post": { "summary": "Post Bar", "operationId": "barPost", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["bar"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "bar" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "post", - "weight": 233, + "weight": 271, "cookies": false, "type": "", - "demo": "bar/post.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a post request.", + "demo": "bar\/post.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a post request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "\/mock\/tests\/bar", + "offline-key": "{required}", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -169,10 +234,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["required", "default", "z"] + "required": [ + "required", + "default", + "z" + ] } } ] @@ -180,32 +251,55 @@ "put": { "summary": "Put Bar", "operationId": "barPut", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["bar"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "bar" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "put", - "weight": 235, + "weight": 273, "cookies": false, "type": "", - "demo": "bar/put.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a put request.", + "demo": "bar\/put.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a put request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -230,10 +324,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["required", "default", "z"] + "required": [ + "required", + "default", + "z" + ] } } ] @@ -241,32 +341,55 @@ "patch": { "summary": "Patch Bar", "operationId": "barPatch", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["bar"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "bar" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "patch", - "weight": 234, + "weight": 272, "cookies": false, "type": "", - "demo": "bar/patch.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a patch request.", + "demo": "bar\/patch.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a patch request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -291,10 +414,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["required", "default", "z"] + "required": [ + "required", + "default", + "z" + ] } } ] @@ -302,32 +431,55 @@ "delete": { "summary": "Delete Bar", "operationId": "barDelete", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["bar"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "bar" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "delete", - "weight": 236, + "weight": 274, "cookies": false, "type": "", - "demo": "bar/delete.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a delete request.", + "demo": "bar\/delete.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a delete request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -352,45 +504,74 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["required", "default", "z"] + "required": [ + "required", + "default", + "z" + ] } } ] } }, - "/mock/tests/foo": { + "\/mock\/tests\/foo": { "get": { "summary": "Get Foo", "operationId": "fooGet", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["foo"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "foo" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "get", - "weight": 227, + "weight": 265, "cookies": false, "type": "", - "demo": "foo/get.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a get request.", + "demo": "foo\/get.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a get request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "x", @@ -414,7 +595,9 @@ "required": true, "type": "array", "collectionFormat": "multi", - "items": { "type": "string" }, + "items": { + "type": "string" + }, "in": "query" } ] @@ -422,32 +605,55 @@ "post": { "summary": "Post Foo", "operationId": "fooPost", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["foo"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "foo" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "post", - "weight": 228, + "weight": 266, "cookies": false, "type": "", - "demo": "foo/post.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a post request.", + "demo": "foo\/post.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a post request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -472,10 +678,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["x", "y", "z"] + "required": [ + "x", + "y", + "z" + ] } } ] @@ -483,32 +695,55 @@ "put": { "summary": "Put Foo", "operationId": "fooPut", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["foo"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "foo" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "put", - "weight": 230, + "weight": 268, "cookies": false, "type": "", - "demo": "foo/put.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a put request.", + "demo": "foo\/put.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a put request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -533,10 +768,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["x", "y", "z"] + "required": [ + "x", + "y", + "z" + ] } } ] @@ -544,32 +785,55 @@ "patch": { "summary": "Patch Foo", "operationId": "fooPatch", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["foo"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "foo" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "patch", - "weight": 229, + "weight": 267, "cookies": false, "type": "", - "demo": "foo/patch.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a patch request.", + "demo": "foo\/patch.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a patch request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -594,10 +858,16 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["x", "y", "z"] + "required": [ + "x", + "y", + "z" + ] } } ] @@ -605,32 +875,55 @@ "delete": { "summary": "Delete Foo", "operationId": "fooDelete", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["foo"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "foo" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "delete", - "weight": 231, + "weight": 269, "cookies": false, "type": "", - "demo": "foo/delete.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a delete request.", + "demo": "foo\/delete.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a delete request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "payload", @@ -655,352 +948,777 @@ "description": "Sample array param", "default": null, "x-example": null, - "items": { "type": "string" } + "items": { + "type": "string" + } } }, - "required": ["x", "y", "z"] + "required": [ + "x", + "y", + "z" + ] } } ] } }, - "/mock/tests/general/400-error": { + "\/mock\/tests\/general\/400-error": { "get": { "summary": "400 Error", "operationId": "generalError400", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "400": { "description": "Error", - "schema": { "$ref": "#/definitions/error" } + "schema": { + "$ref": "#\/definitions\/error" + } } }, "x-appwrite": { "method": "error400", - "weight": 245, + "weight": 285, "cookies": false, "type": "", - "demo": "general/error400.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a 400 failed request.", + "demo": "general\/error400.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a 400 failed request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/500-error": { + "\/mock\/tests\/general\/500-error": { "get": { "summary": "500 Error", "operationId": "generalError500", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "500": { "description": "Error", - "schema": { "$ref": "#/definitions/error" } + "schema": { + "$ref": "#\/definitions\/error" + } } }, "x-appwrite": { "method": "error500", - "weight": 246, + "weight": 286, "cookies": false, "type": "", - "demo": "general/error500.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a 500 failed request.", + "demo": "general\/error500.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a 500 failed request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/502-error": { + "\/mock\/tests\/general\/502-error": { "get": { "summary": "502 Error", "operationId": "generalError502", - "consumes": ["application/json"], - "produces": ["text/plain"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "text\/plain" + ], + "tags": [ + "general" + ], "description": "", "responses": { "502": { "description": "Any", - "schema": { "$ref": "#/definitions/any" } + "schema": { + "$ref": "#\/definitions\/any" + } } }, "x-appwrite": { "method": "error502", - "weight": 247, + "weight": 287, "cookies": false, "type": "", - "demo": "general/error502.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a 502 bad gateway.", + "demo": "general\/error502.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a 502 bad gateway.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client"], + "platforms": [ + "client" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [] }] + "security": [ + { + "Project": [] + } + ] } }, - "/mock/tests/general/download": { + "\/mock\/tests\/general\/download": { "get": { "summary": "Download File", "operationId": "generalDownload", - "consumes": ["application/json"], - "produces": ["*/*"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "*\/*" + ], + "tags": [ + "general" + ], "description": "", "responses": { - "200": { "description": "File", "schema": { "type": "file" } } + "200": { + "description": "File", + "schema": { + "type": "file" + } + } }, "x-appwrite": { "method": "download", - "weight": 237, + "weight": 276, "cookies": false, "type": "location", - "demo": "general/download.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a file download request.", + "demo": "general\/download.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a file download request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/empty": { + "\/mock\/tests\/general\/empty": { "get": { "summary": "Empty Response", "operationId": "generalEmpty", - "consumes": ["application/json"], + "consumes": [ + "application\/json" + ], "produces": [], - "tags": ["general"], + "tags": [ + "general" + ], "description": "", - "responses": { "204": { "description": "No content" } }, + "responses": { + "204": { + "description": "No content" + } + }, "x-appwrite": { "method": "empty", - "weight": 243, + "weight": 282, + "cookies": false, + "type": "", + "demo": "general\/empty.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock an empty response.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "public", + "platforms": [ + "client", + "server", + "server" + ], + "packaging": false, + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } + }, + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] + } + }, + "\/mock\/tests\/general\/enum": { + "post": { + "summary": "Enum Test", + "operationId": "generalEnum", + "consumes": [ + "application\/json" + ], + "produces": [], + "tags": [ + "general" + ], + "description": "", + "responses": { + "500": { + "description": "File", + "schema": { + "type": "file" + } + } + }, + "x-appwrite": { + "method": "enum", + "weight": 284, "cookies": false, "type": "", - "demo": "general/empty.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock an empty response.", + "demo": "general\/enum.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock an enum parameter.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], + "parameters": [ + { + "name": "payload", + "in": "body", + "schema": { + "type": "object", + "properties": { + "mockType": { + "type": "string", + "description": "Sample string param", + "default": null, + "x-example": "first", + "enum": [ + "first", + "second", + "third" + ], + "x-enum-name": null, + "x-enum-keys": [] + } + }, + "required": [ + "mockType" + ] + } + } + ] } }, - "/mock/tests/general/get-cookie": { + "\/mock\/tests\/general\/get-cookie": { "get": { "summary": "Get Cookie", "operationId": "generalGetCookie", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "getCookie", - "weight": 242, + "weight": 281, "cookies": false, "type": "", - "demo": "general/get-cookie.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a cookie response.", + "demo": "general\/get-cookie.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a cookie response.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/headers": { + "\/mock\/tests\/general\/headers": { "get": { "summary": "Get headers", "operationId": "generalHeaders", - "consumes": ["application/json"], + "consumes": [ + "application\/json" + ], "produces": [], - "tags": ["general"], + "tags": [ + "general" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "headers", - "weight": 244, + "weight": 275, "cookies": false, "type": "", - "demo": "general/headers.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterReturn headers from the request", + "demo": "general\/headers.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterReturn headers from the request", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] + } + }, + "\/mock\/tests\/general\/nullable": { + "post": { + "summary": "Nullable Test", + "operationId": "generalNullable", + "consumes": [ + "application\/json" + ], + "produces": [], + "tags": [ + "general" + ], + "description": "", + "responses": { + "500": { + "description": "File", + "schema": { + "type": "file" + } + } + }, + "x-appwrite": { + "method": "nullable", + "weight": 283, + "cookies": false, + "type": "", + "demo": "general\/nullable.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a nullable parameter.", + "rate-limit": 0, + "rate-time": 3600, + "rate-key": "url:{url},ip:{ip}", + "scope": "public", + "platforms": [ + "client", + "server", + "server" + ], + "packaging": false, + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } + }, + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], + "parameters": [ + { + "name": "payload", + "in": "body", + "schema": { + "type": "object", + "properties": { + "required": { + "type": "string", + "description": "Sample string param", + "default": null, + "x-example": "[REQUIRED]" + }, + "nullable": { + "type": "string", + "description": "Sample string param", + "default": null, + "x-example": "[NULLABLE]", + "x-nullable": true + }, + "optional": { + "type": "string", + "description": "Sample string param", + "default": "", + "x-example": "[OPTIONAL]" + } + }, + "required": [ + "required", + "nullable" + ] + } + } + ] } }, - "/mock/tests/general/redirect": { + "\/mock\/tests\/general\/redirect": { "get": { "summary": "Redirect", "operationId": "generalRedirect", - "consumes": ["application/json"], - "produces": ["text/html"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "text\/html" + ], + "tags": [ + "general" + ], "description": "", - "responses": { "301": { "description": "No content" } }, + "responses": { + "301": { + "description": "No content" + } + }, "x-appwrite": { "method": "redirect", - "weight": 239, + "weight": 278, "cookies": false, "type": "", - "demo": "general/redirect.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a redirect request.", + "demo": "general\/redirect.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a redirect request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/redirect/done": { + "\/mock\/tests\/general\/redirect\/done": { "get": { "summary": "Redirected", "operationId": "generalRedirected", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "redirected", - "weight": 240, + "weight": 279, "cookies": false, "type": "", - "demo": "general/redirected.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a redirected request.", + "demo": "general\/redirected.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a redirected request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/set-cookie": { + "\/mock\/tests\/general\/set-cookie": { "get": { "summary": "Set Cookie", "operationId": "generalSetCookie", - "consumes": ["application/json"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "application\/json" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "setCookie", - "weight": 241, + "weight": 280, "cookies": false, "type": "", - "demo": "general/set-cookie.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a set cookie request.", + "demo": "general\/set-cookie.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a set cookie request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }] + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ] } }, - "/mock/tests/general/upload": { + "\/mock\/tests\/general\/upload": { "post": { "summary": "Upload File", "operationId": "generalUpload", - "consumes": ["multipart/form-data"], - "produces": ["application/json"], - "tags": ["general"], + "consumes": [ + "multipart\/form-data" + ], + "produces": [ + "application\/json" + ], + "tags": [ + "general" + ], "description": "", "responses": { "200": { "description": "Mock", - "schema": { "$ref": "#/definitions/mock" } + "schema": { + "$ref": "#\/definitions\/mock" + } } }, "x-appwrite": { "method": "upload", - "weight": 238, + "weight": 277, "cookies": false, "type": "", - "demo": "general/upload.md", - "edit": "https://github.com/appwrite/appwrite/edit/masterMock a file upload request.", + "demo": "general\/upload.md", + "edit": "https:\/\/github.com\/appwrite\/appwrite\/edit\/masterMock a file upload request.", "rate-limit": 0, "rate-time": 3600, "rate-key": "url:{url},ip:{ip}", "scope": "public", - "platforms": ["client", "server", "server"], + "platforms": [ + "client", + "server", + "server" + ], "packaging": false, - "auth": { "Project": [] } + "offline-model": "", + "offline-key": "", + "offline-response-key": "$id", + "auth": { + "Project": [] + } }, - "security": [{ "Project": [], "Key": [], "JWT": [] }], + "security": [ + { + "Project": [], + "Key": [], + "JWT": [] + } + ], "parameters": [ { "name": "x", @@ -1024,7 +1742,9 @@ "required": true, "type": "array", "collectionFormat": "multi", - "items": { "type": "string" }, + "items": { + "type": "string" + }, "in": "formData" }, { @@ -1052,7 +1772,9 @@ { "name": "databases", "description": "The Databases service allows you to create structured collections of documents, query and filter lists of documents", - "x-globalAttributes": ["databaseId"] + "x-globalAttributes": [ + "databaseId" + ] }, { "name": "locale", @@ -1069,6 +1791,11 @@ "description": "The Project service allows you to manage all the projects in your Appwrite server.", "x-globalAttributes": [] }, + { + "name": "project", + "description": "The Project service allows you to manage all the projects in your Appwrite server.", + "x-globalAttributes": [] + }, { "name": "storage", "description": "The Storage service allows you to manage your project files.", @@ -1088,6 +1815,26 @@ "name": "functions", "description": "The Functions Service allows you view, create and manage your Cloud Functions.", "x-globalAttributes": [] + }, + { + "name": "proxy", + "description": "The Proxy Service allows you to configure actions for your domains beyond DNS configuration.", + "x-globalAttributes": [] + }, + { + "name": "graphql", + "description": "The GraphQL API allows you to query and mutate your Appwrite server using GraphQL.", + "x-globalAttributes": [] + }, + { + "name": "console", + "description": "The Console service allows you to interact with console relevant informations.", + "x-globalAttributes": [] + }, + { + "name": "migrations", + "description": "The Migrations service allows you to migrate third-party data to your Appwrite project.", + "x-globalAttributes": [] } ], "definitions": { @@ -1112,7 +1859,7 @@ }, "type": { "type": "string", - "description": "Error type. You can learn more about all the error types at https://appwrite.io/docs/error-codes#errorTypes", + "description": "Error type. You can learn more about all the error types at https:\/\/appwrite.io\/docs\/error-codes#errorTypes", "x-example": "not_found" }, "version": { @@ -1121,7 +1868,12 @@ "x-example": "1.0" } }, - "required": ["message", "code", "type", "version"] + "required": [ + "message", + "code", + "type", + "version" + ] }, "mock": { "description": "Mock", @@ -1133,11 +1885,13 @@ "x-example": "Success" } }, - "required": ["result"] + "required": [ + "result" + ] } }, "externalDocs": { "description": "Full API docs, specs and tutorials", - "url": "https://appwrite.io/docs" + "url": "https:\/\/appwrite.io\/docs" } } \ No newline at end of file From 37a7eb4c6239ac63b249d50d21d38f5c14179783 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Sep 2023 19:02:40 -0400 Subject: [PATCH 58/98] Fix node tests --- tests/languages/node/test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/languages/node/test.js b/tests/languages/node/test.js index c6da69fae..0846402d3 100644 --- a/tests/languages/node/test.js +++ b/tests/languages/node/test.js @@ -13,10 +13,7 @@ async function start() { let MockType = appwrite.MockType; // Init SDK - let client = new appwrite.Client() - .addHeader('Origin', 'http://localhost') - .setEndpoint('https://192.168.0.33/v1') - .setSelfSigned(); + let client = new appwrite.Client(); let foo = new appwrite.Foo(client); let bar = new appwrite.Bar(client); @@ -72,11 +69,11 @@ async function start() { response = await general.upload('string', 123, ['string in array'], InputFile.fromPath(__dirname + '/../../resources/large_file.mp4', 'large_file.mp4')); console.log(response.result); - let buffer = (await (await fs.open('./tests/resources/file.png')).read()).buffer; + let buffer= await fs.readFile('./tests/resources/file.png'); response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'file.png')) console.log(response.result) - buffer = (await (await fs.open('./tests/resources/large_file.mp4')).read()).buffer; + buffer = await fs.readFile('./tests/resources/large_file.mp4'); response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'large_file.mp4')) console.log(response.result) From dea507e3d6d9bdb56021c57f55d0ad5e65a56e54 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Sep 2023 19:02:56 -0400 Subject: [PATCH 59/98] Fix Kotlin missing import --- tests/languages/android/Tests.kt | 1 + tests/languages/kotlin/Tests.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/languages/android/Tests.kt b/tests/languages/android/Tests.kt index 3b59e8cca..ca51002a3 100644 --- a/tests/languages/android/Tests.kt +++ b/tests/languages/android/Tests.kt @@ -8,6 +8,7 @@ import io.appwrite.Permission import io.appwrite.Role import io.appwrite.ID import io.appwrite.Query +import io.appwrite.enums.MockType import io.appwrite.extensions.fromJson import io.appwrite.extensions.toJson import io.appwrite.models.Error diff --git a/tests/languages/kotlin/Tests.kt b/tests/languages/kotlin/Tests.kt index 034c9325b..96e77b3b6 100644 --- a/tests/languages/kotlin/Tests.kt +++ b/tests/languages/kotlin/Tests.kt @@ -5,6 +5,7 @@ import io.appwrite.Permission import io.appwrite.Role import io.appwrite.ID import io.appwrite.Query +import io.appwrite.enums.MockType import io.appwrite.exceptions.AppwriteException import io.appwrite.extensions.fromJson import io.appwrite.extensions.toJson From 500df5f5313bc01c5bd08136aa99f0ebdd497fca Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Sep 2023 19:04:05 -0400 Subject: [PATCH 60/98] Fix PHP missing import --- templates/php/src/Enums/Enum.php.twig | 2 ++ tests/languages/php/test.php | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index fa3735aa0..ea36c6e64 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -2,6 +2,8 @@ namespace {{ spec.title | caseUcfirst }}\Enums; +use JsonSerializable; + class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { private string $value; diff --git a/tests/languages/php/test.php b/tests/languages/php/test.php index e3cd83597..c2eb581ef 100644 --- a/tests/languages/php/test.php +++ b/tests/languages/php/test.php @@ -8,10 +8,10 @@ include __DIR__ . '/../../sdks/php/src/Appwrite/Role.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/ID.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/AppwriteException.php'; +include __DIR__ . '/../../sdks/php/src/Appwrite/Enums/MockType.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/Services/Foo.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/Services/Bar.php'; include __DIR__ . '/../../sdks/php/src/Appwrite/Services/General.php'; -include __DIR__ . '/../../sdks/php/src/Appwrite/Enums/MockType.php'; use Appwrite\AppwriteException; use Appwrite\Client; @@ -20,6 +20,7 @@ use Appwrite\Permission; use Appwrite\Role; use Appwrite\ID; +use Appwrite\Enums\MockType; use Appwrite\Services\Bar; use Appwrite\Services\Foo; use Appwrite\Services\General; @@ -84,7 +85,7 @@ $response = $general->upload('string', 123, ['string in array'], InputFile::withPath(__DIR__ .'/../../resources/large_file.mp4')); echo "{$response['result']}\n"; -$response = $general->enum(MockType::FIRST); +$response = $general->enum(MockType::$FIRST); echo "{$response['result']}\n"; try { From f0a6352dd051f24e7a108cafe3dc9294e4a7e186 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 8 Sep 2023 19:04:26 -0400 Subject: [PATCH 61/98] WIP add dart enum library --- templates/dart/lib/enums.dart.twig | 6 ++++++ templates/dart/lib/src/enums/enum.dart.twig | 22 +++++++++++---------- templates/node/lib/client.js.twig | 17 ++++++++-------- 3 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 templates/dart/lib/enums.dart.twig diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig new file mode 100644 index 000000000..de07da0bf --- /dev/null +++ b/templates/dart/lib/enums.dart.twig @@ -0,0 +1,6 @@ +/// {{spec.title | caseUcfirst}} Models +library {{ language.params.packageName }}.enums; + +{% for definition in spec.definitions %} +part 'src/enums/{{definition.name | caseSnake}}.dart'; +{% endfor %} \ No newline at end of file diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index 29c574c3e..ec119d764 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -1,13 +1,15 @@ -part of {{ language.params.packageName }}; +part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { - {% for value in enum.enum %} -{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %}, -{% endif %} -{% if loop.last %};{% endif %} - {% endfor %} - -final String value; -const {{ enum.name | caseUcfirst | overrideIdentifier }}(this.value); + {%~ for value in enum.enum %} + {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %},{% else %};{% endif %} + + {%~ endfor %} + + const {{ enum.name | caseUcfirst | overrideIdentifier }}({ + required this.value + }); + + final String value; } \ No newline at end of file diff --git a/templates/node/lib/client.js.twig b/templates/node/lib/client.js.twig index b2538e8e8..9cf723f53 100644 --- a/templates/node/lib/client.js.twig +++ b/templates/node/lib/client.js.twig @@ -17,24 +17,24 @@ class Client { 'x-sdk-platform': '{{ sdk.platform }}', 'x-sdk-language': '{{ language.name | caseLower }}', 'x-sdk-version': '{{ sdk.version }}', -{% for key,header in spec.global.defaultHeaders %} + {%~ for key,header in spec.global.defaultHeaders %} '{{key}}' : '{{header}}', -{% endfor %} + {%~ endfor %} }; this.selfSigned = false; } -{% for header in spec.global.headers %} + {%~ for header in spec.global.headers %} /** * Set {{header.key | caseUcfirst}} * -{% if header.description %} + {%~ if header.description %} * {{header.description}} * -{% endif %} + {%~ endif %} * @param {string} {{header.key | caseLower}} * - * @return self + * @return Client */ set{{header.key | caseUcfirst}}({{header.key | caseLower}}) { this.addHeader('{{header.name}}', {{header.key | caseLower}}); @@ -42,7 +42,7 @@ class Client { return this; } -{% endfor %} + {%~ endfor %} /** * Set self signed. * @@ -85,7 +85,6 @@ class Client { process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; } - headers = Object.assign({}, this.headers, headers); let contentType = headers['content-type'].toLowerCase(); @@ -125,8 +124,10 @@ class Client { json: (contentType.startsWith('application/json')), responseType: responseType }; + try { let response = await axios(options); + return response.data; } catch(error) { if('response' in error && error.response !== undefined) { From 7eab7910220ff336db99b77ab769e7df6320fc32 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 29 Sep 2023 02:11:59 +1300 Subject: [PATCH 62/98] Fix dart enums --- src/SDK/Language/Dart.php | 18 ++++++++++++++++-- templates/dart/lib/enums.dart.twig | 6 +++--- templates/dart/lib/package.dart.twig | 4 +--- templates/dart/lib/services/service.dart.twig | 2 +- templates/dart/lib/src/enums/enum.dart.twig | 4 +++- tests/languages/cli/test.js | 4 ++++ tests/languages/dart/tests.dart | 10 +++++++--- tests/languages/flutter/tests.dart | 2 +- tests/resources/spec.json | 10 +++++++++- 9 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 2d79980c2..0257fcd9b 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -112,7 +112,13 @@ public function getKeywords(): array */ public function getIdentifierOverrides(): array { - return ['Function' => 'Func', 'default' => 'xdefault', 'required' => 'xrequired', 'async' => 'xasync']; + return [ + 'Function' => 'Func', + 'default' => 'xdefault', + 'required' => 'xrequired', + 'async' => 'xasync', + 'enum' => 'xenum', + ]; } /** @@ -122,7 +128,10 @@ public function getIdentifierOverrides(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return 'enums.' . \ucfirst($parameter['enumName']); + } + if (!empty($parameter['enumValues'])) { + return 'enums.' . \ucfirst($parameter['name']); } switch ($parameter['type']) { case self::TYPE_INTEGER: @@ -389,6 +398,11 @@ public function getFiles(): array 'destination' => '/lib/models.dart', 'template' => 'dart/lib/models.dart.twig', ], + [ + 'scope' => 'default', + 'destination' => '/lib/enums.dart', + 'template' => 'dart/lib/enums.dart.twig', + ], [ 'scope' => 'service', 'destination' => '/lib/services/{{service.name | caseDash}}.dart', diff --git a/templates/dart/lib/enums.dart.twig b/templates/dart/lib/enums.dart.twig index de07da0bf..4980d4b5e 100644 --- a/templates/dart/lib/enums.dart.twig +++ b/templates/dart/lib/enums.dart.twig @@ -1,6 +1,6 @@ -/// {{spec.title | caseUcfirst}} Models +/// {{spec.title | caseUcfirst}} Enums library {{ language.params.packageName }}.enums; -{% for definition in spec.definitions %} -part 'src/enums/{{definition.name | caseSnake}}.dart'; +{% for enum in spec.enums %} +part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} \ No newline at end of file diff --git a/templates/dart/lib/package.dart.twig b/templates/dart/lib/package.dart.twig index ad4e6d43d..648964076 100644 --- a/templates/dart/lib/package.dart.twig +++ b/templates/dart/lib/package.dart.twig @@ -13,6 +13,7 @@ import 'src/service.dart'; import 'src/input_file.dart'; import 'src/upload_progress.dart'; import 'models.dart' as models; +import 'enums.dart' as enums; export 'src/response.dart'; export 'src/client.dart'; @@ -27,6 +28,3 @@ part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; {% endfor %} -{% for enum in spec.enums %} -part 'src/enums/{{enum | caseSnake}}.dart'; -{% endfor %} diff --git a/templates/dart/lib/services/service.dart.twig b/templates/dart/lib/services/service.dart.twig index 71cba9ccc..7a953bee2 100644 --- a/templates/dart/lib/services/service.dart.twig +++ b/templates/dart/lib/services/service.dart.twig @@ -19,7 +19,7 @@ class {{ service.name | caseUcfirst }} extends Service { {%~ if method.description %} {{ method.description | dartComment }} {% endif %} - {% if method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { + {% if method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { final String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %}; {% if 'multipart/form-data' in method.consumes %} diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index ec119d764..d75f958d6 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -3,7 +3,7 @@ part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseCamel | replace({'-': ''})}}('{{ value }}'){% if not loop.last %},{% else %};{% endif %} + {{ key | caseCamel | replace({'-': ''})}}(value: '{{ value }}'){% if not loop.last %},{% else %};{% endif %} {%~ endfor %} @@ -12,4 +12,6 @@ enum {{ enum.name | caseUcfirst | overrideIdentifier }} { }); final String value; + + String toJson() => value; } \ No newline at end of file diff --git a/tests/languages/cli/test.js b/tests/languages/cli/test.js index 782fe357f..9ea5de6e5 100644 --- a/tests/languages/cli/test.js +++ b/tests/languages/cli/test.js @@ -47,6 +47,10 @@ console.log(output.split('\n')[0].split(" : ")[1]); output = execSync("node index general upload --x string --y 123 --z string in array --file ../../resources/large_file.mp4", { stdio: 'pipe'}).toString(); console.log(output.split('\n')[0].split(" : ")[1]); +// Skip extra tests for CLI +console.log('POST:/v1/mock/tests/general/upload:passed') +console.log('POST:/v1/mock/tests/general/upload:passed') + execSync("node index general empty", { stdio: 'pipe'}); output = execSync("node index general headers", { stdio: 'pipe'}).toString(); diff --git a/tests/languages/dart/tests.dart b/tests/languages/dart/tests.dart index b79c84697..850eba320 100644 --- a/tests/languages/dart/tests.dart +++ b/tests/languages/dart/tests.dart @@ -1,5 +1,9 @@ import '../lib/packageName.dart'; import '../lib/models.dart'; +import '../lib/enums.dart'; +import '../lib/src/input_file.dart'; + +import 'dart:io'; void main() async { Client client = Client(); @@ -59,19 +63,19 @@ void main() async { response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - var resource = new File.fromUri(Uri.parse('../../resources/file.png')); + var resource = File.fromUri(Uri.parse('../../resources/file.png')); var bytes = await resource.readAsBytes(); file = InputFile.fromBytes(bytes: bytes, filename: 'file.png'); response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - resource = new File.fromUri(Uri.parse('../../resources/large_file.mp4')); + resource = File.fromUri(Uri.parse('../../resources/large_file.mp4')); bytes = await resource.readAsBytes(); file = InputFile.fromBytes(bytes: bytes, filename: 'large_file.mp4'); response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - response = await general.enum(MockType.FIRST); + response = await general.xenum(mockType: MockType.first); print(response.result); try { diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index 2338e7a18..0daa5ef20 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -98,7 +98,7 @@ void main() async { response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - response = await general.enum(MockType.FIRST); + response = await general.xenum(MockType.FIRST); print(response.result); try { diff --git a/tests/resources/spec.json b/tests/resources/spec.json index d8dccd7d8..6076d59b5 100644 --- a/tests/resources/spec.json +++ b/tests/resources/spec.json @@ -1236,12 +1236,20 @@ "consumes": [ "application\/json" ], - "produces": [], + "produces": [ + "application\/json" + ], "tags": [ "general" ], "description": "", "responses": { + "200": { + "description": "Mock", + "schema": { + "$ref": "#\/definitions\/mock" + } + }, "500": { "description": "File", "schema": { From e0614e49ea74b56e5f8f86f6931b80d357d81d47 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 2 Oct 2023 13:51:02 +1300 Subject: [PATCH 63/98] Fix .NET enums --- src/SDK/Language/Dart.php | 6 +-- src/SDK/Language/Deno.php | 34 +++++++-------- src/SDK/Language/DotNet.php | 42 +++++++++---------- src/SDK/Language/Go.php | 30 +++++++------ src/SDK/Language/JS.php | 6 +++ src/SDK/Language/Kotlin.php | 37 +++++++--------- src/SDK/Language/Node.php | 22 +++++++++- src/SDK/Language/PHP.php | 35 ++++++---------- src/SDK/Language/Python.php | 17 +++++++- src/SDK/Language/Ruby.php | 29 +++++++------ src/SDK/Language/Swift.php | 37 +++++++--------- src/SDK/Language/Web.php | 7 +++- .../dotnet/src/Appwrite/Appwrite.csproj.twig | 2 +- templates/dotnet/src/Appwrite/Client.cs.twig | 7 +++- .../Converters/ValueClassConverter.cs.twig | 40 ++++++++++++++++++ .../dotnet/src/Appwrite/Enums/Enums.cs.twig | 5 --- .../flutter/lib/services/service.dart.twig | 2 +- tests/Base.php | 1 - tests/languages/dart/tests.dart | 2 +- tests/languages/deno/tests.ts | 2 + tests/languages/dotnet/Tests.cs | 8 +++- tests/languages/flutter/tests.dart | 12 ++++-- tests/languages/node/test.js | 14 ++++--- tests/languages/php/test.php | 7 ++-- tests/languages/ruby/tests.rb | 4 +- tests/languages/web/index.html | 5 ++- tests/languages/web/node.js | 5 ++- 27 files changed, 242 insertions(+), 176 deletions(-) create mode 100644 templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 0257fcd9b..9e78f174b 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -133,7 +133,7 @@ public function getTypeName(array $parameter): string if (!empty($parameter['enumValues'])) { return 'enums.' . \ucfirst($parameter['name']); } - switch ($parameter['type']) { + switch ($parameter['type'] ?? '') { case self::TYPE_INTEGER: return 'int'; case self::TYPE_STRING: @@ -151,9 +151,9 @@ public function getTypeName(array $parameter): string return 'Map'; case self::TYPE_NUMBER: return 'double'; + default: + return $parameter['type']; } - - return $parameter['type']; } /** diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 84327921b..2c433e8d7 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -108,28 +108,22 @@ public function getFiles(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); } - - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'number'; - case self::TYPE_STRING: - return 'string'; - case self::TYPE_FILE: - return 'InputFile'; - case self::TYPE_BOOLEAN: - return 'boolean'; - case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { - return $this->getTypeName($parameter['array']) . '[]'; - } - return 'string[]'; - case self::TYPE_OBJECT: - return 'object'; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } - - return $parameter['type']; + return match ($parameter['type']) { + self::TYPE_INTEGER => 'number', + self::TYPE_STRING => 'string', + self::TYPE_FILE => 'InputFile', + self::TYPE_BOOLEAN => 'boolean', + self::TYPE_ARRAY => $parameter['array']['type'] + ? $this->getTypeName($parameter['array']) . '[]' + : 'string[]', + self::TYPE_OBJECT => 'object', + default => $parameter['type'] + }; } /** diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 84c92e7ad..28d56f501 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -152,30 +152,23 @@ public function getIdentifierOverrides(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); } - - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'long'; - case self::TYPE_NUMBER: - return 'double'; - case self::TYPE_STRING: - return 'string'; - case self::TYPE_FILE: - return 'InputFile'; - case self::TYPE_BOOLEAN: - return 'bool'; - case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { - return 'List<' . $this->getTypeName($parameter['array']) . '>'; - } - return 'List'; - case self::TYPE_OBJECT: - return 'object'; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } - - return $parameter['type']; + return match ($parameter['type']) { + self::TYPE_INTEGER => 'long', + self::TYPE_NUMBER => 'double', + self::TYPE_STRING => 'string', + self::TYPE_BOOLEAN => 'bool', + self::TYPE_FILE => 'InputFile', + self::TYPE_ARRAY => $parameter['array']['type'] + ? 'List<' . $this->getTypeName($parameter['array']) . '>' + : 'List', + self::TYPE_OBJECT => 'object', + default => $parameter['type'] + }; } /** @@ -365,6 +358,11 @@ public function getFiles(): array 'destination' => '/src/{{ spec.title | caseUcfirst }}/Role.cs', 'template' => 'dotnet/src/Appwrite/Role.cs.twig', ], + [ + 'scope' => 'default', + 'destination' => '/src/{{ spec.title | caseUcfirst }}/Converters/ValueClassConverter.cs', + 'template' => 'dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig', + ], [ 'scope' => 'default', 'destination' => '/src/{{ spec.title | caseUcfirst }}/Extensions/Extensions.cs', diff --git a/src/SDK/Language/Go.php b/src/SDK/Language/Go.php index ebb4347e6..f60be7efa 100644 --- a/src/SDK/Language/Go.php +++ b/src/SDK/Language/Go.php @@ -108,23 +108,21 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'int'; - case self::TYPE_NUMBER: - return 'float64'; - case self::TYPE_FILE: - case self::TYPE_STRING: - return 'string'; - case self::TYPE_BOOLEAN: - return 'bool'; - case self::TYPE_OBJECT: - return 'interface{}'; - case self::TYPE_ARRAY: - return '[]interface{}'; + if (isset($parameter['enumName'])) { + return \ucfirst($parameter['enumName']); } - - return $parameter['type']; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); + } + return match ($parameter['type']) { + self::TYPE_INTEGER => 'int', + self::TYPE_NUMBER => 'float64', + self::TYPE_FILE, self::TYPE_STRING => 'string', + self::TYPE_BOOLEAN => 'bool', + self::TYPE_OBJECT => 'interface{}', + self::TYPE_ARRAY => '[]interface{}', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index a4a0ba64c..6079fa8fb 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -124,6 +124,12 @@ public function getIdentifierOverrides(): array */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return \ucfirst($parameter['enumName']); + } + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); + } switch ($parameter['type']) { case self::TYPE_INTEGER: diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index ac0ca0ebd..fd238222d 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -106,30 +106,23 @@ public function getIdentifierOverrides(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); } - - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'Long'; - case self::TYPE_NUMBER: - return 'Double'; - case self::TYPE_STRING: - return 'String'; - case self::TYPE_FILE: - return 'InputFile'; - case self::TYPE_BOOLEAN: - return 'Boolean'; - case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { - return 'List<' . $this->getTypeName($parameter['array']) . '>'; - } - return 'List'; - case self::TYPE_OBJECT: - return 'Any'; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } - - return $parameter['type']; + return match ($parameter['type']) { + self::TYPE_INTEGER => 'Long', + self::TYPE_NUMBER => 'Double', + self::TYPE_STRING => 'String', + self::TYPE_FILE => 'InputFile', + self::TYPE_BOOLEAN => 'Boolean', + self::TYPE_ARRAY => $parameter['array']['type'] + ? 'List<' . $this->getTypeName($parameter['array']) . '>' + : 'List', + self::TYPE_OBJECT => 'Any', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index 2f135e18e..624501186 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -19,6 +19,24 @@ public function getName(): string */ public function getTypeName(array $parameter): string { + if (isset($parameter['enumName'])) { + return \ucfirst($parameter['enumName']); + } + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); + } + return match ($parameter['type']) { + self::TYPE_INTEGER, + self::TYPE_NUMBER => 'number', + self::TYPE_STRING => 'string', + self::TYPE_FILE => 'InputFile', + self::TYPE_BOOLEAN => 'boolean', + self::TYPE_OBJECT => 'object', + self::TYPE_ARRAY => $parameter['array']['type'] + ? $this->getTypeName($parameter['array']) . '[]' + : 'string[]', + default => $parameter['type'], + }; switch ($parameter['type']) { case self::TYPE_INTEGER: case self::TYPE_NUMBER: @@ -30,9 +48,9 @@ public function getTypeName(array $parameter): string return 'string[]'; case self::TYPE_FILE: return 'InputFile'; + default: + return $parameter['type']; } - - return $parameter['type']; } /** diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 6b1078ac3..c67fdbac9 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -228,30 +228,21 @@ public function getFiles(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); } - - switch ($parameter['type']) { - case self::TYPE_STRING: - $type = 'string'; - break; - case self::TYPE_BOOLEAN: - $type = 'bool'; - break; - case self::TYPE_NUMBER: - case self::TYPE_INTEGER: - $type = 'int'; - break; - case self::TYPE_ARRAY: - case self::TYPE_OBJECT: - $type = 'array'; - break; - case self::TYPE_FILE: - $type = 'InputFile'; - break; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } - - return $type; + return match ($parameter['type']) { + self::TYPE_STRING => 'string', + self::TYPE_BOOLEAN => 'bool', + self::TYPE_NUMBER, + self::TYPE_INTEGER => 'int', + self::TYPE_ARRAY, + self::TYPE_OBJECT => 'array', + self::TYPE_FILE => 'InputFile', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index e0901a60b..5e118999c 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -199,7 +199,22 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { - throw new Exception('Method not supported for Python SDKs'); + if (isset($parameter['enumName'])) { + return \ucfirst($parameter['enumName']); + } + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); + } + return match ($parameter['type'] ?? '') { + self::TYPE_FILE => 'InputFile', + self::TYPE_NUMBER, + self::TYPE_INTEGER => 'float', + self::TYPE_BOOLEAN => 'bool', + self::TYPE_STRING => 'str', + self::TYPE_ARRAY => 'list', + self::TYPE_OBJECT => 'dict', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index f94b4a9a3..022a6788b 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -197,22 +197,21 @@ public function getFiles(): array */ public function getTypeName(array $parameter): string { - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'Integer'; - case self::TYPE_NUMBER: - return 'Float'; - case self::TYPE_STRING: - return 'String'; - case self::TYPE_ARRAY: - return 'Array'; - case self::TYPE_OBJECT: - return 'Hash'; - case self::TYPE_BOOLEAN: - return ''; - default: - return $parameter['type']; + if (isset($parameter['enumName'])) { + return \ucfirst($parameter['enumName']); } + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); + } + return match ($parameter['type']) { + self::TYPE_INTEGER => 'Integer', + self::TYPE_NUMBER => 'Float', + self::TYPE_STRING => 'String', + self::TYPE_ARRAY => 'Array', + self::TYPE_OBJECT => 'Hash', + self::TYPE_BOOLEAN => '', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index ed08dc969..0579c4529 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -299,30 +299,23 @@ public function getFiles(): array public function getTypeName(array $parameter): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); } - - switch ($parameter['type']) { - case self::TYPE_INTEGER: - return 'Int'; - case self::TYPE_NUMBER: - return 'Double'; - case self::TYPE_STRING: - return 'String'; - case self::TYPE_FILE: - return 'InputFile'; - case self::TYPE_BOOLEAN: - return 'Bool'; - case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { - return '[' . $this->getTypeName($parameter['array']) . ']'; - } - return '[Any]'; - case self::TYPE_OBJECT: - return 'Any'; + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } - - return $parameter['type']; + return match ($parameter['type']) { + self::TYPE_INTEGER => 'Int', + self::TYPE_NUMBER => 'Double', + self::TYPE_STRING => 'String', + self::TYPE_FILE => 'InputFile', + self::TYPE_BOOLEAN => 'Bool', + self::TYPE_ARRAY => $parameter['array']['type'] + ? '[' . $this->getTypeName($parameter['array']) . ']' + : '[Any]', + self::TYPE_OBJECT => 'Any', + default => $parameter['type'], + }; } /** diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index a45471885..dd8325cbd 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -180,7 +180,10 @@ public function getParamExample(array $param): string public function getTypeName(array $parameter, array $method = []): string { if (isset($parameter['enumName'])) { - return $parameter['enumName']; + return \ucfirst($parameter['enumName']); + } + if (!empty($parameter['enumValues'])) { + return \ucfirst($parameter['name']); } switch ($parameter['type']) { case self::TYPE_INTEGER: @@ -208,8 +211,8 @@ public function getTypeName(array $parameter, array $method = []): string return "Partial>"; } } + break; } - return $parameter['type']; } diff --git a/templates/dotnet/src/Appwrite/Appwrite.csproj.twig b/templates/dotnet/src/Appwrite/Appwrite.csproj.twig index 74673a1eb..9d5539f32 100644 --- a/templates/dotnet/src/Appwrite/Appwrite.csproj.twig +++ b/templates/dotnet/src/Appwrite/Appwrite.csproj.twig @@ -20,7 +20,7 @@ - + diff --git a/templates/dotnet/src/Appwrite/Client.cs.twig b/templates/dotnet/src/Appwrite/Client.cs.twig index 277d6ecd4..df6e01abf 100644 --- a/templates/dotnet/src/Appwrite/Client.cs.twig +++ b/templates/dotnet/src/Appwrite/Client.cs.twig @@ -10,6 +10,7 @@ using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; +using {{ spec.title | caseUcfirst }}.Converters; using {{ spec.title | caseUcfirst }}.Extensions; using {{ spec.title | caseUcfirst }}.Models; @@ -34,7 +35,8 @@ namespace {{ spec.title | caseUcfirst }} ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new List { - new StringEnumConverter() + new StringEnumConverter(new CamelCaseNamingStrategy()), + new ValueClassConverter() } }; @@ -44,7 +46,8 @@ namespace {{ spec.title | caseUcfirst }} ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new List { - new StringEnumConverter() + new StringEnumConverter(new CamelCaseNamingStrategy()), + new ValueClassConverter() } }; diff --git a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig new file mode 100644 index 000000000..d46cc93b8 --- /dev/null +++ b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig @@ -0,0 +1,40 @@ +using System; +using {{ spec.title | caseUcfirst }}.Enums; +using Newtonsoft.Json; + +namespace {{ spec.title | caseUcfirst }}.Converters +{ + public class ValueClassConverter : JsonConverter { + + public override bool CanConvert(Type objectType) + { + return {% for enum in spec.enums %}typeof({{ enum | caseUcfirst }}).IsAssignableFrom(objectType){% if not loop.last %} ||{% else %};{% endif %} + + {%~ endfor %} + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var value = (string)reader.Value; + var constructor = objectType.GetConstructor(new[] { typeof(string) }); + var obj = constructor.Invoke(new object[] { value }); + + return Convert.ChangeType(obj, objectType); + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var type = value.GetType(); + var property = type.GetProperty("Value"); + var propertyValue = property.GetValue(value); + + if (propertyValue == null) + { + writer.WriteNull(); + return; + } + + writer.WriteValue(propertyValue); + } + } +} diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig index 5ce71ab47..0d61472dc 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig @@ -15,10 +15,5 @@ namespace {{ spec.title | caseUcfirst }}.Enums {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} public static {{ enum.name | caseUcfirst | overrideIdentifier }} {{ key | caseUcfirst | strip }} => new {{ enum.name | caseUcfirst | overrideIdentifier }}("{{ value }}"); {% endfor %} - - public override string ToString() - { - return Value; - } } } diff --git a/templates/flutter/lib/services/service.dart.twig b/templates/flutter/lib/services/service.dart.twig index 03be8528e..d2df0bc8d 100644 --- a/templates/flutter/lib/services/service.dart.twig +++ b/templates/flutter/lib/services/service.dart.twig @@ -20,7 +20,7 @@ class {{ service.name | caseUcfirst }} extends Service { {%~ if method.description %} {{ method.description|dartComment }} {% endif %} - {% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { + {% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { {% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %}; {% if 'multipart/form-data' in method.consumes %} diff --git a/tests/Base.php b/tests/Base.php index 3cb4ea122..8e9b558c9 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -192,7 +192,6 @@ public function testHTTPSuccess(): void echo \implode("\n", $output); - $this->assertEquals(\count($this->expectedOutput), \count($output)); $this->assertEquals([], \array_diff($this->expectedOutput, $output)); } diff --git a/tests/languages/dart/tests.dart b/tests/languages/dart/tests.dart index 850eba320..ce964496a 100644 --- a/tests/languages/dart/tests.dart +++ b/tests/languages/dart/tests.dart @@ -6,7 +6,7 @@ import '../lib/src/input_file.dart'; import 'dart:io'; void main() async { - Client client = Client(); + Client client = Client().setSelfSigned(true); Foo foo = Foo(client); Bar bar = Bar(client); General general = General(client); diff --git a/tests/languages/deno/tests.ts b/tests/languages/deno/tests.ts index 890e1565b..8e4c93ca1 100644 --- a/tests/languages/deno/tests.ts +++ b/tests/languages/deno/tests.ts @@ -12,6 +12,8 @@ async function start() { // Init SDK let client = new appwrite.Client() + .addHeader("Origin", "http://localhost") + .setSelfSigned(true) let foo = new appwrite.Foo(client) let bar = new appwrite.Bar(client) diff --git a/tests/languages/dotnet/Tests.cs b/tests/languages/dotnet/Tests.cs index 3fffdb579..27ea0f277 100644 --- a/tests/languages/dotnet/Tests.cs +++ b/tests/languages/dotnet/Tests.cs @@ -5,6 +5,7 @@ using Appwrite; using Appwrite.Models; +using Appwrite.Enums; using Appwrite.Services; using NUnit.Framework; @@ -21,7 +22,10 @@ public void Setup() [Test] public async Task Test1() { - var client = new Client(); + var client = new Client() + .AddHeader("Origin", "http://localhost") + .SetSelfSigned(true); + var foo = new Foo(client); var bar = new Bar(client); var general = new General(client); @@ -77,7 +81,7 @@ public async Task Test1() mock = await general.Upload("string", 123, new List() { "string in array" }, InputFile.FromStream(info.OpenRead(), "large_file.mp4", "video/mp4")); TestContext.WriteLine(mock.Result); - mock = await general.Enum(MockType.First) + mock = await general.Enum(MockType.First); TestContext.WriteLine(mock.Result); try diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index 0daa5ef20..56a0e9ba1 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -4,6 +4,8 @@ import 'package:path_provider_platform_interface/path_provider_platform_interfac import '../lib/packageName.dart'; import '../lib/client_io.dart'; import '../lib/models.dart'; +import '../lib/enums.dart'; +import '../lib/src/input_file.dart'; import 'dart:io'; class FakePathProvider extends PathProviderPlatform { @@ -17,7 +19,9 @@ class FakePathProvider extends PathProviderPlatform { void main() async { WidgetsFlutterBinding.ensureInitialized(); PathProviderPlatform.instance = FakePathProvider(); - Client client = Client(); + Client client = Client() + .addHeader("Origin", "http://localhost") + .setSelfSigned(true); Foo foo = Foo(client); Bar bar = Bar(client); General general = General(client); @@ -86,19 +90,19 @@ void main() async { response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - var resource = new File.fromUri(Uri.parse('../../resources/file.png')); + var resource = File.fromUri(Uri.parse('../../resources/file.png')); var bytes = await resource.readAsBytes(); file = InputFile.fromBytes(bytes: bytes, filename: 'file.png'); response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - resource = new File.fromUri(Uri.parse('../../resources/large_file.mp4')); + resource = File.fromUri(Uri.parse('../../resources/large_file.mp4')); bytes = await resource.readAsBytes(); file = InputFile.fromBytes(bytes: bytes, filename: 'large_file.mp4'); response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - response = await general.xenum(MockType.FIRST); + response = await general.xenum(mockType: MockType.FIRST); print(response.result); try { diff --git a/tests/languages/node/test.js b/tests/languages/node/test.js index 0846402d3..b2e0008d8 100644 --- a/tests/languages/node/test.js +++ b/tests/languages/node/test.js @@ -13,7 +13,9 @@ async function start() { let MockType = appwrite.MockType; // Init SDK - let client = new appwrite.Client(); + let client = new appwrite.Client() + .addHeader("Origin", "http://localhost") + .setSelfSigned(true); let foo = new appwrite.Foo(client); let bar = new appwrite.Bar(client); @@ -60,9 +62,6 @@ async function start() { response = await general.redirect(); console.log(response.result); - response = await general.enum(MockType.first); - console.log(response.result) - response = await general.upload('string', 123, ['string in array'], InputFile.fromPath(__dirname + '/../../resources/file.png', 'file.png')); console.log(response.result); @@ -71,11 +70,14 @@ async function start() { let buffer= await fs.readFile('./tests/resources/file.png'); response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'file.png')) - console.log(response.result) + console.log(response.result); buffer = await fs.readFile('./tests/resources/large_file.mp4'); response = await general.upload('string', 123, ['string in array'], appwrite.InputFile.fromBuffer(buffer, 'large_file.mp4')) - console.log(response.result) + console.log(response.result); + + response = await general.enum(MockType.first); + console.log(response.result); try { response = await general.error400(); diff --git a/tests/languages/php/test.php b/tests/languages/php/test.php index c2eb581ef..89ad3c3c5 100644 --- a/tests/languages/php/test.php +++ b/tests/languages/php/test.php @@ -25,13 +25,14 @@ use Appwrite\Services\Foo; use Appwrite\Services\General; -$client = new Client(); +$client = (new Client()) + ->addHeader("Origin", "http://localhost") + ->setSelfSigned(); + $foo = new Foo($client); $bar = new Bar($client); $general = new General($client); -$client->addHeader('Origin', 'http://localhost'); - echo "\nTest Started\n"; // Foo Service diff --git a/tests/languages/ruby/tests.rb b/tests/languages/ruby/tests.rb index ce6d9ff4d..35a6ebc2e 100644 --- a/tests/languages/ruby/tests.rb +++ b/tests/languages/ruby/tests.rb @@ -3,7 +3,9 @@ include Appwrite client = Client.new -client.add_header('Origin', 'http://localhost') +client + .add_header('Origin', 'http://localhost') + .set_self_signed() foo = Foo.new(client) bar = Bar.new(client) diff --git a/tests/languages/web/index.html b/tests/languages/web/index.html index 2b24c296b..9396dd64d 100644 --- a/tests/languages/web/index.html +++ b/tests/languages/web/index.html @@ -21,7 +21,10 @@ let responseRealtime = 'Realtime failed!'; // Init SDK const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = Appwrite; - const client = new Client(); + const client = new Client() + .addHeader("Origin", "http://localhost") + .setSelfSigned(true); + const foo = new Foo(client); const bar = new Bar(client); const general = new General(client); diff --git a/tests/languages/web/node.js b/tests/languages/web/node.js index 129c674a3..c25dcb695 100644 --- a/tests/languages/web/node.js +++ b/tests/languages/web/node.js @@ -4,7 +4,10 @@ async function start() { let response; console.log('\nTest Started'); - const client = new Client(); + const client = new Client() + .addHeader("Origin", "http://localhost") + .setSelfSigned(true); + const foo = new Foo(client); const bar = new Bar(client); const general = new General(client); From 09536a872ce56301ac4a2c4b283e0f8b788acd5d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 2 Oct 2023 14:48:10 +1300 Subject: [PATCH 64/98] Fix PHP enums --- templates/php/src/Enums/Enum.php.twig | 21 ++++++++++++--------- templates/php/src/Services/Service.php.twig | 13 ++++++++++--- tests/languages/php/test.php | 2 +- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index ea36c6e64..c3c156318 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,18 +6,15 @@ use JsonSerializable; class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { + {%~ for value in enum.enum %} + private static {{ enum.name | caseUcfirst }} ${{ value | caseSnake | caseUpper | strip }}; + {%~ endfor %} + private string $value; - public function __construct(string $value) + private function __construct(string $value) { $this->value = $value; - -{% for value in enum.enum %} -{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - if (!isset(self::${{ key | caseUpper | strip }})) { - self::${{ key | caseUpper | strip }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); - } -{% endfor %} } public function __toString(): string @@ -32,6 +29,12 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializ {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static {{ enum.name | caseUcfirst | overrideIdentifier }} ${{ key | caseUpper | strip }}; + public static function {{ key | caseSnake | caseUpper }}(): {{ enum.name | caseUcfirst | overrideIdentifier}} + { + if (!isset(self::${{ key | caseUpper | strip }})) { + self::${{ key | caseSnake | caseUpper | strip }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); + } + return self::${{ key | caseSnake | caseUpper | strip }}; + } {% endfor %} } \ No newline at end of file diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index 087a64da2..2261d6067 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -9,9 +9,16 @@ use {{ spec.title | caseUcfirst }}\InputFile; {% set added = [] %} {% for method in service.methods %} {% for parameter in method.parameters.all %} -{% if parameter.enumName is not null and parameter.enumName not in added %} -use {{ spec.title | caseUcfirst }}\Enums\{{ parameter.enumName | caseUcfirst }}; -{% set added = added|merge([parameter.enumName]) %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +use {{ spec.title | caseUcfirst }}\Enums\{{ name | caseUcfirst }}; +{% set added = added|merge([name]) %} +{% endif %} {% endif %} {% endfor %} {% endfor %} diff --git a/tests/languages/php/test.php b/tests/languages/php/test.php index 89ad3c3c5..ed95ea92c 100644 --- a/tests/languages/php/test.php +++ b/tests/languages/php/test.php @@ -86,7 +86,7 @@ $response = $general->upload('string', 123, ['string in array'], InputFile::withPath(__DIR__ .'/../../resources/large_file.mp4')); echo "{$response['result']}\n"; -$response = $general->enum(MockType::$FIRST); +$response = $general->enum(MockType::FIRST()); echo "{$response['result']}\n"; try { From e649b30ea76ac0f9c5c2b0fbe141fc880ca08c5d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 2 Oct 2023 16:25:04 +1300 Subject: [PATCH 65/98] Fix Python enums --- src/SDK/Language/Python.php | 15 +++++++++++++++ templates/python/package/client.py.twig | 12 ++++++------ .../package/encoders/value_class_encoder.py.twig | 13 +++++++++++++ templates/swift/Package.swift.twig | 7 ++++++- .../swift/Sources/Services/Service.swift.twig | 1 + tests/languages/python/tests.py | 3 +-- 6 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 templates/python/package/encoders/value_class_encoder.py.twig diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index 5e118999c..318f84785 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -169,6 +169,21 @@ public function getFiles(): array 'destination' => '{{ spec.title | caseSnake}}/services/__init__.py', 'template' => 'python/package/services/__init__.py.twig', ], + [ + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/encoders/__init__.py', + 'template' => 'python/package/services/__init__.py.twig', + ], + [ + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/enums/__init__.py', + 'template' => 'python/package/services/__init__.py.twig', + ], + [ + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/encoders/value_class_encoder.py', + 'template' => 'python/package/encoders/value_class_encoder.py.twig', + ], [ 'scope' => 'service', 'destination' => '{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.py', diff --git a/templates/python/package/client.py.twig b/templates/python/package/client.py.twig index 48ed835a4..db5e74799 100644 --- a/templates/python/package/client.py.twig +++ b/templates/python/package/client.py.twig @@ -1,8 +1,10 @@ import io -import requests +import json import os +import requests from .input_file import InputFile from .exception import {{spec.title | caseUcfirst}}Exception +from .encoders.value_class_encoder import ValueClassEncoder class Client: def __init__(self): @@ -53,7 +55,6 @@ class Client: params = {k: v for k, v in params.items() if v is not None} # Remove None values from params dictionary data = {} - json = {} files = {} stringify = False @@ -64,8 +65,7 @@ class Client: params = {} if headers['content-type'].startswith('application/json'): - json = data - data = {} + data = json.dumps(data, cls=ValueClassEncoder) if headers['content-type'].startswith('multipart/form-data'): del headers['content-type'] @@ -74,14 +74,14 @@ class Client: if isinstance(data[key], InputFile): files[key] = (data[key].filename, data[key].data) del data[key] + data = self.flatten(data, stringify=stringify) response = None try: response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554 method=method, url=self._endpoint + path, params=self.flatten(params, stringify=stringify), - data=self.flatten(data), - json=json, + data=data, files=files, headers=headers, verify=(not self._self_signed), diff --git a/templates/python/package/encoders/value_class_encoder.py.twig b/templates/python/package/encoders/value_class_encoder.py.twig new file mode 100644 index 000000000..bc84aa453 --- /dev/null +++ b/templates/python/package/encoders/value_class_encoder.py.twig @@ -0,0 +1,13 @@ +import json +{%~ for enum in spec.enums %} +from ..enums.{{ enum | caseSnake }} import {{ enum | caseUcfirst | overrideIdentifier }} +{%~ endfor %} + +class ValueClassEncoder(json.JSONEncoder): + def default(self, o): + {%~ for enum in spec.enums %} + if isinstance(o, {{ enum | caseUcfirst | overrideIdentifier }}): + return o.value + + {%~ endfor %} + return super().default(o) \ No newline at end of file diff --git a/templates/swift/Package.swift.twig b/templates/swift/Package.swift.twig index d5ee138ec..07320adee 100644 --- a/templates/swift/Package.swift.twig +++ b/templates/swift/Package.swift.twig @@ -13,7 +13,12 @@ let package = Package( products: [ .library( name: "{{spec.title | caseUcfirst}}", - targets: ["{{spec.title | caseUcfirst}}", "{{spec.title | caseUcfirst}}Models", "JSONCodable"] + targets: [ + "{{spec.title | caseUcfirst}}", + "{{spec.title | caseUcfirst}}Enums", + "{{spec.title | caseUcfirst}}Models", + "JSONCodable" + ] ), ], dependencies: [ diff --git a/templates/swift/Sources/Services/Service.swift.twig b/templates/swift/Sources/Services/Service.swift.twig index aad435162..65aaab844 100644 --- a/templates/swift/Sources/Services/Service.swift.twig +++ b/templates/swift/Sources/Services/Service.swift.twig @@ -2,6 +2,7 @@ import AsyncHTTPClient import Foundation import NIO import JSONCodable +import {{spec.title | caseUcfirst}}Enums import {{spec.title | caseUcfirst}}Models /// {{ service.description }} diff --git a/tests/languages/python/tests.py b/tests/languages/python/tests.py index 6a21c44cd..f0be4c13d 100644 --- a/tests/languages/python/tests.py +++ b/tests/languages/python/tests.py @@ -8,11 +8,10 @@ from appwrite.permission import Permission from appwrite.role import Role from appwrite.id import ID -from appwrite.mock_type import MockType +from appwrite.enums.mock_type import MockType import os.path - client = Client() foo = Foo(client) bar = Bar(client) From 1a8f151c7117a619a4fb41fa5610df7ce939af04 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 2 Oct 2023 19:05:06 +1300 Subject: [PATCH 66/98] Fix swift enums --- src/SDK/Language/Swift.php | 4 +++- templates/swift/Sources/Client.swift.twig | 7 ++++++- templates/swift/Sources/Enums/Enum.swift.twig | 17 ++++++++++++----- .../swift/Sources/Services/Service.swift.twig | 4 ++-- tests/languages/swift/Tests.swift | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 0579c4529..211f148bf 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -95,7 +95,9 @@ public function getKeywords(): array */ public function getIdentifierOverrides(): array { - return []; + return [ + 'enum' => 'xenum' + ]; } /** diff --git a/templates/swift/Sources/Client.swift.twig b/templates/swift/Sources/Client.swift.twig index 8be157d3a..89bcffc3c 100644 --- a/templates/swift/Sources/Client.swift.twig +++ b/templates/swift/Sources/Client.swift.twig @@ -446,7 +446,12 @@ open class Client { || param is [Bool: Any] { encodedParams[key] = param } else { - encodedParams[key] = try! (param as! Encodable).toJson() + let value = try! (param as! Encodable).toJson() + + let range = value.index(value.startIndex, offsetBy: 1)..{% endif %}( + open func {{ method.name | caseCamel | overrideIdentifier }}{% if method.responseModel | hasGenericType(spec) %}{% endif %}( {%~ for parameter in method.parameters.all %} {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} diff --git a/tests/languages/swift/Tests.swift b/tests/languages/swift/Tests.swift index 285918889..3268c188c 100644 --- a/tests/languages/swift/Tests.swift +++ b/tests/languages/swift/Tests.swift @@ -104,7 +104,7 @@ class Tests: XCTestCase { print(error.localizedDescription) } - mock = try await general.enum(.first) + mock = try await general.xenum(mockType: .first) print(mock.result) do { From 35e69e709548fe4623a243cb3b84fd5f99040bf6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 3 Oct 2023 16:16:38 +1300 Subject: [PATCH 67/98] Fix dart test --- tests/languages/dart/tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/languages/dart/tests.dart b/tests/languages/dart/tests.dart index ce964496a..d4ed7e889 100644 --- a/tests/languages/dart/tests.dart +++ b/tests/languages/dart/tests.dart @@ -6,7 +6,7 @@ import '../lib/src/input_file.dart'; import 'dart:io'; void main() async { - Client client = Client().setSelfSigned(true); + Client client = Client().setSelfSigned(); Foo foo = Foo(client); Bar bar = Bar(client); General general = General(client); From 6c19700c4e08f1b87984af7237eef31be580fe80 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 3 Oct 2023 16:56:20 +1300 Subject: [PATCH 68/98] Fix deno enums --- templates/deno/src/enums/enum.ts.twig | 6 +++--- templates/deno/src/services/service.ts.twig | 19 +++++++++++++++---- tests/languages/deno/tests.ts | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/templates/deno/src/enums/enum.ts.twig b/templates/deno/src/enums/enum.ts.twig index b94dd355f..34724aba0 100644 --- a/templates/deno/src/enums/enum.ts.twig +++ b/templates/deno/src/enums/enum.ts.twig @@ -1,6 +1,6 @@ export enum {{ enum.name | caseUcfirst | overrideIdentifier }} { - {% for value in enum.enum %} - {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {%~ for value in enum.enum %} + {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} {{ key | caseUcfirst | replace({'-': ''}) }} = '{{ value }}', -{% endfor %} + {%~ endfor %} } \ No newline at end of file diff --git a/templates/deno/src/services/service.ts.twig b/templates/deno/src/services/service.ts.twig index e829afd5f..9e3b6da70 100644 --- a/templates/deno/src/services/service.ts.twig +++ b/templates/deno/src/services/service.ts.twig @@ -34,9 +34,16 @@ import type { Models } from '../models.d.ts'; {% set added = [] %} {% for method in service.methods %} {% for parameter in method.parameters.all %} -{% if parameter.enumName is not null and parameter.enumName not in added %} -import type {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; -{% set added = added|merge([parameter.enumName]) %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import { {{ name | caseUcfirst }} } from '../enums/{{ name | caseDash }}.ts'; +{% set added = added|merge([name]) %} +{% endif %} {% endif %} {% endfor %} {% endfor %} @@ -137,7 +144,11 @@ export class {{ service.name | caseUcfirst }} extends Service { } const start = ((currentChunk - 1) * Client.CHUNK_SIZE); - const end = start + currentPosition; + let end = start + currentPosition; + + if (end === size) { + end -= 1; + } if(!lastUpload || currentChunk !== 1) { apiHeaders['content-range'] = 'bytes ' + start + '-' + end + '/' + size; diff --git a/tests/languages/deno/tests.ts b/tests/languages/deno/tests.ts index 8e4c93ca1..05d241b71 100644 --- a/tests/languages/deno/tests.ts +++ b/tests/languages/deno/tests.ts @@ -13,7 +13,6 @@ async function start() { // Init SDK let client = new appwrite.Client() .addHeader("Origin", "http://localhost") - .setSelfSigned(true) let foo = new appwrite.Foo(client) let bar = new appwrite.Bar(client) @@ -89,7 +88,7 @@ async function start() { // @ts-ignore console.log(response.result) - response = await general.enum(MockType.first) + response = await general.enum(appwrite.MockType.First) // @ts-ignore console.log(response.result) From 8ad9cbce1252583d2cffadc0f5a24cf3ed1cd9b0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 3 Oct 2023 17:03:56 +1300 Subject: [PATCH 69/98] Fix node 12 test --- tests/languages/node/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/languages/node/test.js b/tests/languages/node/test.js index b2e0008d8..70f94829a 100644 --- a/tests/languages/node/test.js +++ b/tests/languages/node/test.js @@ -1,7 +1,7 @@ const appwrite = require('../../sdks/node/index'); const InputFile = require('../../sdks/node/lib/inputFile'); -const fs = require('fs/promises'); +const fs = require('fs').promises; async function start() { var response; From df4c5d6494543a8a80084528b70780e248e60be0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 13:09:42 +1300 Subject: [PATCH 70/98] Fix web enum tests --- templates/web/src/services/template.ts.twig | 13 ++++++++++--- tests/languages/web/index.html | 2 +- tests/languages/web/node.js | 7 ++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/templates/web/src/services/template.ts.twig b/templates/web/src/services/template.ts.twig index dafc60297..70f4c4a53 100644 --- a/templates/web/src/services/template.ts.twig +++ b/templates/web/src/services/template.ts.twig @@ -5,9 +5,16 @@ import type { UploadProgress, Payload } from '../client'; {% set added = [] %} {% for method in service.methods %} {% for parameter in method.parameters.all %} -{% if parameter.enumName is not null and parameter.enumName not in added %} -import type {{ '{' }} {{ parameter.enumName }} {{ '}' }} from '../enums/{{ parameter.enumName | caseDash }}.ts'; -{% set added = added|merge([parameter.enumName]) %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import { {{ name | caseUcfirst }} } from '../enums/{{ name | caseDash }}'; +{% set added = added|merge([name]) %} +{% endif %} {% endif %} {% endfor %} {% endfor %} diff --git a/tests/languages/web/index.html b/tests/languages/web/index.html index 9396dd64d..f277a4551 100644 --- a/tests/languages/web/index.html +++ b/tests/languages/web/index.html @@ -91,7 +91,7 @@ console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip InputFile tests console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip InputFile tests - response = await general.enum(MockType.first); + response = await general.enum(MockType.First); console.log(response.result); try { diff --git a/tests/languages/web/node.js b/tests/languages/web/node.js index c25dcb695..323ae2d11 100644 --- a/tests/languages/web/node.js +++ b/tests/languages/web/node.js @@ -4,10 +4,7 @@ async function start() { let response; console.log('\nTest Started'); - const client = new Client() - .addHeader("Origin", "http://localhost") - .setSelfSigned(true); - + const client = new Client(); const foo = new Foo(client); const bar = new Bar(client); const general = new General(client); @@ -52,7 +49,7 @@ async function start() { console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip file upload test on Node.js console.log('POST:/v1/mock/tests/general/upload:passed'); // Skip big file upload test on Node.js - response = await general.enum(MockType.first); + response = await general.enum(MockType.First); console.log(response.result); try { From b0d9a63109b16080f7b2e3a2fefabe377b18afa1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 15:18:36 +1300 Subject: [PATCH 71/98] Fix array type checks --- src/SDK/Language/Dart.php | 2 +- src/SDK/Language/Deno.php | 2 +- src/SDK/Language/DotNet.php | 4 ++-- src/SDK/Language/GraphQL.php | 2 +- src/SDK/Language/JS.php | 2 +- src/SDK/Language/Kotlin.php | 2 +- src/SDK/Language/Node.php | 16 +--------------- src/SDK/Language/Swift.php | 8 +++++++- src/SDK/Language/Web.php | 2 +- 9 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 9e78f174b..174295fa5 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -143,7 +143,7 @@ public function getTypeName(array $parameter): string case self::TYPE_BOOLEAN: return 'bool'; case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { + if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { return 'List<' . $this->getTypeName($parameter['array']) . '>'; } return 'List'; diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 2c433e8d7..d3036024b 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -118,7 +118,7 @@ public function getTypeName(array $parameter): string self::TYPE_STRING => 'string', self::TYPE_FILE => 'InputFile', self::TYPE_BOOLEAN => 'boolean', - self::TYPE_ARRAY => $parameter['array']['type'] + self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) ? $this->getTypeName($parameter['array']) . '[]' : 'string[]', self::TYPE_OBJECT => 'object', diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index 28d56f501..aa461cddc 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -163,7 +163,7 @@ public function getTypeName(array $parameter): string self::TYPE_STRING => 'string', self::TYPE_BOOLEAN => 'bool', self::TYPE_FILE => 'InputFile', - self::TYPE_ARRAY => $parameter['array']['type'] + self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) ? 'List<' . $this->getTypeName($parameter['array']) . '>' : 'List', self::TYPE_OBJECT => 'object', @@ -401,7 +401,7 @@ public function getFiles(): array [ 'scope' => 'enum', 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ enum.name | caseUcfirst | overrideIdentifier }}.cs', - 'template' => 'dotnet/src/Appwrite/Enums/Enums.cs.twig', + 'template' => 'dotnet/src/Appwrite/Enums/Enum.cs.twig', ] ]; } diff --git a/src/SDK/Language/GraphQL.php b/src/SDK/Language/GraphQL.php index 628f7598f..6a62b6c78 100644 --- a/src/SDK/Language/GraphQL.php +++ b/src/SDK/Language/GraphQL.php @@ -34,7 +34,7 @@ public function getTypeName(array $parameter): string $type = 'Bool'; break; case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { + if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { $type = '[' . $this->getTypeName($parameter['array']) . ']'; break; } diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index 6079fa8fb..6c2eb8603 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -136,7 +136,7 @@ public function getTypeName(array $parameter): string case self::TYPE_NUMBER: return 'number'; case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { + if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { return $this->getTypeName($parameter['array']) . '[]'; } return 'string[]'; diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index fd238222d..c17cbed70 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -117,7 +117,7 @@ public function getTypeName(array $parameter): string self::TYPE_STRING => 'String', self::TYPE_FILE => 'InputFile', self::TYPE_BOOLEAN => 'Boolean', - self::TYPE_ARRAY => $parameter['array']['type'] + self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) ? 'List<' . $this->getTypeName($parameter['array']) . '>' : 'List', self::TYPE_OBJECT => 'Any', diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index 624501186..1d2af921f 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -32,25 +32,11 @@ public function getTypeName(array $parameter): string self::TYPE_FILE => 'InputFile', self::TYPE_BOOLEAN => 'boolean', self::TYPE_OBJECT => 'object', - self::TYPE_ARRAY => $parameter['array']['type'] + self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) ? $this->getTypeName($parameter['array']) . '[]' : 'string[]', default => $parameter['type'], }; - switch ($parameter['type']) { - case self::TYPE_INTEGER: - case self::TYPE_NUMBER: - return 'number'; - case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { - return $this->getTypeName($parameter['array']) . '[]'; - } - return 'string[]'; - case self::TYPE_FILE: - return 'InputFile'; - default: - return $parameter['type']; - } } /** diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 211f148bf..d4d4d2eb2 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -312,7 +312,7 @@ public function getTypeName(array $parameter): string self::TYPE_STRING => 'String', self::TYPE_FILE => 'InputFile', self::TYPE_BOOLEAN => 'Bool', - self::TYPE_ARRAY => $parameter['array']['type'] + self::TYPE_ARRAY => (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) ? '[' . $this->getTypeName($parameter['array']) . ']' : '[Any]', self::TYPE_OBJECT => 'Any', @@ -460,6 +460,12 @@ public function getFilters(): array new TwigFilter('hasGenericType', function (string $model, array $spec) { return $this->hasGenericType($model, $spec); }), + new TwigFilter('escapeSwiftKeyword', function ($value) { + if (in_array($value, $this->getKeywords())) { + return "`{$value}`"; + } + return $value; + }), ]; } diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index dd8325cbd..129461921 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -190,7 +190,7 @@ public function getTypeName(array $parameter, array $method = []): string case self::TYPE_NUMBER: return 'number'; case self::TYPE_ARRAY: - if (!empty($parameter['array']['type'])) { + if (!empty(($parameter['array'] ?? [])['type']) && !\is_array($parameter['array']['type'])) { return $this->getTypeName($parameter['array']) . '[]'; } return 'string[]'; From 55b4fa350044127e8b5129c2e2698995a8758e9a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 15:18:59 +1300 Subject: [PATCH 72/98] Fix swift escapes --- templates/swift/Sources/Client.swift.twig | 13 ++++++------- templates/swift/Sources/Enums/Enum.swift.twig | 2 +- templates/swift/Sources/Models/Model.swift.twig | 10 +++++----- templates/swift/Sources/Services/Service.swift.twig | 6 +++--- templates/swift/base/params.twig | 4 ++-- templates/swift/docs/example.md.twig | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/templates/swift/Sources/Client.swift.twig b/templates/swift/Sources/Client.swift.twig index 89bcffc3c..434a4837a 100644 --- a/templates/swift/Sources/Client.swift.twig +++ b/templates/swift/Sources/Client.swift.twig @@ -25,10 +25,10 @@ open class Client { "x-sdk-language": "{{ language.name | caseLower }}", "x-sdk-version": "{{ sdk.version }}"{% if spec.global.defaultHeaders | length > 0 %},{% endif %} -{% for key,header in spec.global.defaultHeaders %} + {%~ for key,header in spec.global.defaultHeaders %} "{{key}}": "{{header}}"{% if not loop.last %},{% endif %} -{% endfor %} + {%~ endfor %} ] open var config: [String: String] = [:] @@ -95,14 +95,14 @@ open class Client { } } -{% for header in spec.global.headers %} + {%~ for header in spec.global.headers %} /// /// Set {{header.key | caseUcfirst}} /// -{% if header.description %} + {%~ if header.description %} /// {{header.description}} /// -{% endif %} + {%~ endif %} /// @param String value /// /// @return Client @@ -113,7 +113,7 @@ open class Client { return self } -{% endfor %} + {%~ endfor %} /// /// Set self signed @@ -590,7 +590,6 @@ extension Client { } extension Client { - public enum HTTPStatus: Int { case unknown = -1 case ok = 200 diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index 12e0fa3df..98674b1f4 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -3,7 +3,7 @@ import Foundation public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, Codable { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - case {{ key | caseCamel | replace({'-': ''})}} + case {{ key | caseCamel | replace({'-': ''}) | escapeSwiftKeyword }} {%~ endfor %} public func encode(to encoder: Encoder) throws { diff --git a/templates/swift/Sources/Models/Model.swift.twig b/templates/swift/Sources/Models/Model.swift.twig index a8aa18cec..cc3fbe6be 100644 --- a/templates/swift/Sources/Models/Model.swift.twig +++ b/templates/swift/Sources/Models/Model.swift.twig @@ -9,7 +9,7 @@ public class {{ definition | modelType(spec) | raw }} { {%~ for property in definition.properties %} /// {{ property.description }} - public let {{ property.name | escapeKeyword | removeDollarSign }}: {{ property | propertyType(spec) | raw }}{% if not property.required %}?{% endif %} + public let {{ property.name | escapeSwiftKeyword | removeDollarSign }}: {{ property | propertyType(spec) | raw }}{% if not property.required %}?{% endif %} {%~ endfor %} @@ -20,7 +20,7 @@ public class {{ definition | modelType(spec) | raw }} { init( {%~ for property in definition.properties %} - {{ property.name | escapeKeyword | removeDollarSign }}: {{ property | propertyType(spec) | raw }}{% if not property.required %}?{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} + {{ property.name | escapeSwiftKeyword | removeDollarSign }}: {{ property | propertyType(spec) | raw }}{% if not property.required %}?{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} {%~ endfor %} {%~ if definition.additionalProperties %} @@ -28,7 +28,7 @@ public class {{ definition | modelType(spec) | raw }} { {%~ endif %} ) { {%~ for property in definition.properties %} - self.{{ property.name | escapeKeyword | removeDollarSign }} = {{ property.name | escapeKeyword | removeDollarSign }} + self.{{ property.name | escapeSwiftKeyword | removeDollarSign }} = {{ property.name | escapeSwiftKeyword | removeDollarSign }} {%~ endfor %} {%~ if definition.additionalProperties %} self.data = data @@ -38,7 +38,7 @@ public class {{ definition | modelType(spec) | raw }} { public func toMap() -> [String: Any] { return [ {%~ for property in definition.properties %} - "{{ property.name | escapeKeyword }}": {% if property.sub_schema %}{% if property.type == 'array' %}{{property.name | escapeKeyword | removeDollarSign}}.map { $0.toMap() }{% else %}{{property.name | escapeKeyword | removeDollarSign}}.toMap(){% endif %}{% else %}{{property.name | escapeKeyword | removeDollarSign}}{% endif %} as Any{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} + "{{ property.name | escapeSwiftKeyword }}": {% if property.sub_schema %}{% if property.type == 'array' %}{{property.name | escapeSwiftKeyword | removeDollarSign}}.map { $0.toMap() }{% else %}{{property.name | escapeSwiftKeyword | removeDollarSign}}.toMap(){% endif %}{% else %}{{property.name | escapeSwiftKeyword | removeDollarSign}}{% endif %} as Any{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} {%~ endfor %} {%~ if definition.additionalProperties %} @@ -50,7 +50,7 @@ public class {{ definition | modelType(spec) | raw }} { public static func from(map: [String: Any] ) -> {{ definition.name | caseUcfirst }} { return {{ definition.name | caseUcfirst }}( {%~ for property in definition.properties %} - {{ property.name | escapeKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{property.name }}"] as! [[String: Any]]).map { {{property.sub_schema | caseUcfirst}}.from(map: $0) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map: map["{{property.name }}"] as! [String: Any]){% endif %}{% else %}map["{{property.name }}"] as{% if property.required %}!{% else %}?{% endif %} {{ property | propertyType(spec) | raw }}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} + {{ property.name | escapeSwiftKeyword | removeDollarSign }}: {% if property.sub_schema %}{% if property.type == 'array' %}(map["{{property.name }}"] as! [[String: Any]]).map { {{property.sub_schema | caseUcfirst}}.from(map: $0) }{% else %}{{property.sub_schema | caseUcfirst}}.from(map: map["{{property.name }}"] as! [String: Any]){% endif %}{% else %}map["{{property.name }}"] as{% if property.required %}!{% else %}?{% endif %} {{ property | propertyType(spec) | raw }}{% endif %}{% if not loop.last or (loop.last and definition.additionalProperties) %},{% endif %} {%~ endfor %} {%~ if definition.additionalProperties %} diff --git a/templates/swift/Sources/Services/Service.swift.twig b/templates/swift/Sources/Services/Service.swift.twig index b4e46a3f2..3581e61be 100644 --- a/templates/swift/Sources/Services/Service.swift.twig +++ b/templates/swift/Sources/Services/Service.swift.twig @@ -27,7 +27,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ endif %} open func {{ method.name | caseCamel | overrideIdentifier }}{% if method.responseModel | hasGenericType(spec) %}{% endif %}( {%~ for parameter in method.parameters.all %} - {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} + {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} {%~ endfor %} {%~ if method.responseModel | hasGenericType(spec) %} @@ -93,7 +93,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ endif %} open func {{ method.name | caseCamel }}( {%~ for parameter in method.parameters.all %} - {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} + {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} {%~ endfor %} {%~ if 'multipart/form-data' in method.consumes %} @@ -102,7 +102,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { ) async throws -> {{ method | returnType(spec, '[String: AnyCodable]') | raw }} { return try await {{ method.name | caseCamel }}( {%~ for parameter in method.parameters.all %} - {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.name | caseCamel | escapeKeyword }}, + {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter.name | caseCamel | escapeSwiftKeyword }}, {%~ endfor %} nestedType: [String: AnyCodable].self {%~ if 'multipart/form-data' in method.consumes %} diff --git a/templates/swift/base/params.twig b/templates/swift/base/params.twig index 8a959fc2c..bb8917e15 100644 --- a/templates/swift/base/params.twig +++ b/templates/swift/base/params.twig @@ -1,6 +1,6 @@ let apiPath: String = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeKeyword }}{% if parameter.enumName is not null %}.rawValue{% endif %}) + .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeSwiftKeyword }}{% if parameter.enumName is not null %}.rawValue{% endif %}) {%~ endfor %} {%~ if method.parameters.query | merge(method.parameters.body) | length <= 0 %} @@ -10,7 +10,7 @@ {%- else -%} let {%- endif %} apiParams: [String: Any?] = [ {%~ for parameter in method.parameters.query | merge(method.parameters.body) %} - "{{ parameter.name }}": {{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or (method.type == 'location' or method.type == 'webAuth' and method.auth | length > 0) %},{% endif %} + "{{ parameter.name }}": {{ parameter.name | caseCamel | escapeSwiftKeyword }}{% if not loop.last or (method.type == 'location' or method.type == 'webAuth' and method.auth | length > 0) %},{% endif %} {%~ endfor %} {%~ if method.type == 'location' or method.type == 'webAuth' %} diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index 31eca4603..fef8fe0d4 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -17,10 +17,10 @@ let client = Client() let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) -let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} +let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} {% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} - {{parameter.name}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample | escapeKeyword }}{% endif %}{% if not loop.last %},{% endif %} + {{parameter.name}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} {% if loop.last %} ) From d03c2eb734f0f0e4826128360fc8656b21e34fe0 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 15:19:14 +1300 Subject: [PATCH 73/98] Fix .NET enum template name --- .../src/Appwrite/Enums/{Enums.cs.twig => Enum.cs.twig} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename templates/dotnet/src/Appwrite/Enums/{Enums.cs.twig => Enum.cs.twig} (78%) diff --git a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig similarity index 78% rename from templates/dotnet/src/Appwrite/Enums/Enums.cs.twig rename to templates/dotnet/src/Appwrite/Enums/Enum.cs.twig index 0d61472dc..1e8721f88 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enums.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig @@ -11,9 +11,9 @@ namespace {{ spec.title | caseUcfirst }}.Enums Value = value; } -{% for value in enum.enum %} -{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {%~ for value in enum.enum %} + {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} public static {{ enum.name | caseUcfirst | overrideIdentifier }} {{ key | caseUcfirst | strip }} => new {{ enum.name | caseUcfirst | overrideIdentifier }}("{{ value }}"); -{% endfor %} + {%~ endfor %} } } From cb7a6ada890b9507ea28b0e0d922bcda3f5bb98d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 15:49:11 +1300 Subject: [PATCH 74/98] Add spec to type name filter --- src/SDK/Language.php | 2 +- src/SDK/Language/Dart.php | 2 +- src/SDK/Language/Deno.php | 2 +- src/SDK/Language/DotNet.php | 2 +- src/SDK/Language/Go.php | 2 +- src/SDK/Language/GraphQL.php | 2 +- src/SDK/Language/HTTP.php | 2 +- src/SDK/Language/JS.php | 2 +- src/SDK/Language/Kotlin.php | 2 +- src/SDK/Language/Node.php | 2 +- src/SDK/Language/PHP.php | 2 +- src/SDK/Language/Python.php | 2 +- src/SDK/Language/Ruby.php | 2 +- src/SDK/Language/Swift.php | 6 +++--- src/SDK/SDK.php | 4 ++-- templates/swift/Sources/Services/Service.swift.twig | 8 ++++---- 16 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/SDK/Language.php b/src/SDK/Language.php index 0a7a259f7..414b0fc54 100644 --- a/src/SDK/Language.php +++ b/src/SDK/Language.php @@ -41,7 +41,7 @@ abstract public function getFiles(): array; * @param array $parameter * @return string */ - abstract public function getTypeName(array $parameter): string; + abstract public function getTypeName(array $parameter, array $spec = []): string; /** * @param array $param diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 174295fa5..ca0baa98a 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -125,7 +125,7 @@ public function getIdentifierOverrides(): array * @param array $parameter * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return 'enums.' . \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index d3036024b..9a8c6a978 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -105,7 +105,7 @@ public function getFiles(): array * @param array $parameter * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index aa461cddc..af4674efb 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -149,7 +149,7 @@ public function getIdentifierOverrides(): array * @param array $parameter * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Go.php b/src/SDK/Language/Go.php index f60be7efa..60c44f453 100644 --- a/src/SDK/Language/Go.php +++ b/src/SDK/Language/Go.php @@ -106,7 +106,7 @@ public function getFiles(): array * @param array $nestedTypes * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/GraphQL.php b/src/SDK/Language/GraphQL.php index 6a62b6c78..ca4f6735e 100644 --- a/src/SDK/Language/GraphQL.php +++ b/src/SDK/Language/GraphQL.php @@ -16,7 +16,7 @@ public function getName(): string * @param $type * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { $type = ''; diff --git a/src/SDK/Language/HTTP.php b/src/SDK/Language/HTTP.php index 1e674c945..f1abcc4a9 100644 --- a/src/SDK/Language/HTTP.php +++ b/src/SDK/Language/HTTP.php @@ -30,7 +30,7 @@ public function getIdentifierOverrides(): array * @return string * @throws Exception */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { throw new Exception('Method not supported for HTTP APIs'); } diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index 6c2eb8603..38ef8bea7 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -122,7 +122,7 @@ public function getIdentifierOverrides(): array * @param array $nestedTypes * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index c17cbed70..41bc07400 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -103,7 +103,7 @@ public function getIdentifierOverrides(): array * @param $type * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index 1d2af921f..6e55ea482 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -17,7 +17,7 @@ public function getName(): string * @param array $nestedTypes * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index c67fdbac9..7cb84c505 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -225,7 +225,7 @@ public function getFiles(): array * @param array $nestedTypes * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index 318f84785..7f74304ca 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -212,7 +212,7 @@ public function getFiles(): array * @return string * @throws Exception */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index 022a6788b..38112cac6 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -195,7 +195,7 @@ public function getFiles(): array * @param array $nestedTypes * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { return \ucfirst($parameter['enumName']); diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index d4d4d2eb2..02d8290d8 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -298,13 +298,13 @@ public function getFiles(): array * @param array $parameter * @return string */ - public function getTypeName(array $parameter): string + public function getTypeName(array $parameter, array $spec = []): string { if (isset($parameter['enumName'])) { - return \ucfirst($parameter['enumName']); + return ($spec['title'] ?? '') . 'Enums.' . \ucfirst($parameter['enumName']); } if (!empty($parameter['enumValues'])) { - return \ucfirst($parameter['name']); + return ($spec['title'] ?? '') . 'Enums.' . \ucfirst($parameter['name']); } return match ($parameter['type']) { self::TYPE_INTEGER => 'Int', diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 203d06cdf..d8794f2a4 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -137,8 +137,8 @@ public function __construct(Language $language, Spec $spec) $this->twig->addFilter(new TwigFilter('caseArray', function ($value) { return (is_array($value)) ? json_encode($value) : '[]'; }, ['is_safe' => ['html']])); - $this->twig->addFilter(new TwigFilter('typeName', function ($value) { - return $this->language->getTypeName($value); + $this->twig->addFilter(new TwigFilter('typeName', function ($value, $spec = []) { + return $this->language->getTypeName($value, $spec); }, ['is_safe' => ['html']])); $this->twig->addFilter(new TwigFilter('paramDefault', function ($value) { return $this->language->getParamDefault($value); diff --git a/templates/swift/Sources/Services/Service.swift.twig b/templates/swift/Sources/Services/Service.swift.twig index 3581e61be..2e0e7a2cc 100644 --- a/templates/swift/Sources/Services/Service.swift.twig +++ b/templates/swift/Sources/Services/Service.swift.twig @@ -17,7 +17,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { /// {%~ endif %} {%~ for parameter in method.parameters.all %} - /// @param {{ parameter | typeName | raw}} {{ parameter.name | caseCamel }} + /// @param {{ parameter | typeName(spec) | raw}} {{ parameter.name | caseCamel }} {%~ endfor %} /// @throws Exception /// @return array @@ -27,7 +27,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ endif %} open func {{ method.name | caseCamel | overrideIdentifier }}{% if method.responseModel | hasGenericType(spec) %}{% endif %}( {%~ for parameter in method.parameters.all %} - {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} + {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} {%~ endfor %} {%~ if method.responseModel | hasGenericType(spec) %} @@ -83,7 +83,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { /// {%~ endif %} {%~ for parameter in method.parameters.all %} - /// @param {{ parameter | typeName | raw}} {{ parameter.name | caseCamel }} + /// @param {{ parameter | typeName(spec) | raw}} {{ parameter.name | caseCamel }} {%~ endfor %} /// @throws Exception /// @return array @@ -93,7 +93,7 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ endif %} open func {{ method.name | caseCamel }}( {%~ for parameter in method.parameters.all %} - {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} + {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} {%~ endfor %} {%~ if 'multipart/form-data' in method.consumes %} From 8263763b0303901acff282008f67fd9a00498250 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 4 Oct 2023 15:50:36 +1300 Subject: [PATCH 75/98] Remove duplicate file from Apple --- src/SDK/Language/Apple.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/SDK/Language/Apple.php b/src/SDK/Language/Apple.php index eb452ce1e..e3515de48 100644 --- a/src/SDK/Language/Apple.php +++ b/src/SDK/Language/Apple.php @@ -60,11 +60,6 @@ public function getFiles(): array 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/WebSockets/WebSocketClientError.swift', 'template' => '/swift/Sources/WebSockets/WebSocketClientError.swift.twig', ], - [ - 'scope' => 'enum', - 'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Enums/{{ enum.name | caseUcfirst }}.swift', - 'template' => '/swift/Sources/Enums/Enum.swift.twig', - ], // Config for project example-swiftui [ 'scope' => 'default', From c3fd502557e588f35a5bdf3b8314a36d71eb8bdc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 17 Oct 2023 14:39:38 +1300 Subject: [PATCH 76/98] Add enum case key --- src/SDK/Language.php | 15 +- src/SDK/Language/Dart.php | 3 + src/SDK/Language/Deno.php | 11 ++ src/SDK/Language/DotNet.php | 5 +- src/SDK/Language/Go.php | 5 +- src/SDK/Language/JS.php | 10 ++ src/SDK/Language/Kotlin.php | 11 +- src/SDK/Language/PHP.php | 3 + src/SDK/Language/Python.php | 158 ++++++++++-------- src/SDK/Language/Ruby.php | 5 +- src/SDK/Language/Swift.php | 12 +- src/SDK/Language/Web.php | 13 +- src/SDK/SDK.php | 6 - templates/android/docs/java/example.md.twig | 56 +++++-- templates/android/docs/kotlin/example.md.twig | 53 ++++-- .../main/java/io/appwrite/enums/Enum.kt.twig | 2 +- .../appwrite/services/ServiceTemplate.kt.twig | 2 +- templates/dart/docs/example.md.twig | 2 +- templates/dart/lib/src/enums/enum.dart.twig | 2 +- templates/deno/docs/example.md.twig | 2 +- templates/dotnet/base/params.twig | 2 +- templates/dotnet/docs/example.md.twig | 2 +- .../dotnet/src/Appwrite/Enums/Enum.cs.twig | 2 +- templates/flutter/docs/example.md.twig | 6 +- templates/kotlin/docs/java/example.md.twig | 2 +- templates/kotlin/docs/kotlin/example.md.twig | 2 +- .../kotlin/io/appwrite/enums/Enum.kt.twig | 2 +- .../appwrite/services/ServiceTemplate.kt.twig | 2 +- templates/php/docs/example.md.twig | 2 +- templates/php/src/Enums/Enum.php.twig | 10 +- templates/python/docs/example.md.twig | 2 +- templates/ruby/lib/container.rb.twig | 4 + templates/ruby/lib/container/client.rb.twig | 5 +- .../ruby/lib/container/enums/enum.rb.twig | 12 +- templates/swift/base/params.twig | 2 +- templates/swift/base/requests/api.twig | 2 +- templates/swift/docs/example.md.twig | 2 +- templates/web/docs/example.md.twig | 2 +- 38 files changed, 281 insertions(+), 158 deletions(-) diff --git a/src/SDK/Language.php b/src/SDK/Language.php index 414b0fc54..68a90cfbe 100644 --- a/src/SDK/Language.php +++ b/src/SDK/Language.php @@ -84,7 +84,7 @@ public function getFilters(): array return []; } - protected function toUpperCaseWords(string $value): string + protected function toPascalCase(string $value): string { return ucfirst($this->toCamelCase($value)); } @@ -97,4 +97,17 @@ protected function toCamelCase($str): string $str = str_replace(" ", "", $str); return lcfirst($str); } + + protected function toSnakeCase($str): string + { + $str = \preg_replace('/([a-z])([A-Z])/', '$1 $2', $str); + $str = \explode(' ', $str); + $str = \implode('_', $str); + return \strtolower($str); + } + + protected function toUpperSnakeCase($str): string + { + return \strtoupper($this->toSnakeCase($str)); + } } diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index ca0baa98a..b61380a01 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -501,6 +501,9 @@ public function getFilters(): array } return implode("\n", $value); }, ['is_safe' => ['html']]), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toCamelCase($value); + }), ]; } } diff --git a/src/SDK/Language/Deno.php b/src/SDK/Language/Deno.php index 9a8c6a978..e85c439ea 100644 --- a/src/SDK/Language/Deno.php +++ b/src/SDK/Language/Deno.php @@ -2,6 +2,8 @@ namespace Appwrite\SDK\Language; +use Twig\TwigFilter; + class Deno extends JS { /** @@ -179,4 +181,13 @@ public function getParamExample(array $param): string return $output; } + + public function getFilters(): array + { + return [ + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toPascalCase($value); + }), + ]; + } } diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index af4674efb..c077be3f3 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -415,7 +415,10 @@ public function getFilters(): array $value[$key] = " /// " . wordwrap($line, 75, "\n /// "); } return implode("\n", $value); - }, ['is_safe' => ['html']]) + }, ['is_safe' => ['html']]), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toPascalCase($value); + }), ]; } } diff --git a/src/SDK/Language/Go.php b/src/SDK/Language/Go.php index 60c44f453..9ab699d37 100644 --- a/src/SDK/Language/Go.php +++ b/src/SDK/Language/Go.php @@ -245,7 +245,10 @@ public function getFilters(): array $value[$key] = "// " . wordwrap($line, 75, "\n// "); } return implode("\n", $value); - }, ['is_safe' => ['html']]) + }, ['is_safe' => ['html']]), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toUpperSnakeCase($value); + }), ]; } } diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index 38ef8bea7..78ee3dea6 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -3,6 +3,7 @@ namespace Appwrite\SDK\Language; use Appwrite\SDK\Language; +use Twig\TwigFilter; abstract class JS extends Language { @@ -199,4 +200,13 @@ public function getParamDefault(array $param): string return $output; } + + public function getFilters(): array + { + return [ + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toUpperSnakeCase($value); + }), + ]; + } } diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index 41bc07400..4b2d89530 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -439,6 +439,9 @@ public function getFilters(): array new TwigFilter('hasGenericType', function (string $model, array $spec) { return $this->hasGenericType($model, $spec); }), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toUpperSnakeCase($value); + }), ]; } @@ -459,7 +462,7 @@ protected function getReturnType(array $method, array $spec, string $namespace, return 'Any'; } - $ret = $this->toUpperCaseWords($method['responseModel']); + $ret = $this->toPascalCase($method['responseModel']); if ($this->hasGenericType($method['responseModel'], $spec)) { $ret .= '<' . $generic . '>'; @@ -471,15 +474,15 @@ protected function getReturnType(array $method, array $spec, string $namespace, protected function getModelType(array $definition, array $spec, string $generic = 'T'): string { if ($this->hasGenericType($definition['name'], $spec)) { - return $this->toUpperCaseWords($definition['name']) . '<' . $generic . '>'; + return $this->toPascalCase($definition['name']) . '<' . $generic . '>'; } - return $this->toUpperCaseWords($definition['name']); + return $this->toPascalCase($definition['name']); } protected function getPropertyType(array $property, array $spec, string $generic = 'T'): string { if (\array_key_exists('sub_schema', $property)) { - $type = $this->toUpperCaseWords($property['sub_schema']); + $type = $this->toPascalCase($property['sub_schema']); if ($this->hasGenericType($property['sub_schema'], $spec)) { $type .= '<' . $generic . '>'; diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 7cb84c505..80e2f6737 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -389,6 +389,9 @@ public function getFilters(): array new TwigFilter('deviceInfo', function ($value) { return php_uname('s') . '; ' . php_uname('v') . '; ' . php_uname('m'); }), + new TwigFilter('caseEnumKey', function (string $value) { + $this->toUpperSnakeCase($value); + }), ]; } } diff --git a/src/SDK/Language/Python.php b/src/SDK/Language/Python.php index 7f74304ca..891d0d67d 100644 --- a/src/SDK/Language/Python.php +++ b/src/SDK/Language/Python.php @@ -4,6 +4,7 @@ use Appwrite\SDK\Language; use Exception; +use Twig\TwigFilter; class Python extends Language { @@ -90,119 +91,119 @@ public function getFiles(): array { return [ [ - 'scope' => 'default', - 'destination' => 'README.md', - 'template' => 'python/README.md.twig', + 'scope' => 'default', + 'destination' => 'README.md', + 'template' => 'python/README.md.twig', ], [ - 'scope' => 'default', - 'destination' => 'CHANGELOG.md', - 'template' => 'python/CHANGELOG.md.twig', + 'scope' => 'default', + 'destination' => 'CHANGELOG.md', + 'template' => 'python/CHANGELOG.md.twig', ], [ - 'scope' => 'default', - 'destination' => 'LICENSE', - 'template' => 'python/LICENSE.twig', + 'scope' => 'default', + 'destination' => 'LICENSE', + 'template' => 'python/LICENSE.twig', ], [ - 'scope' => 'default', - 'destination' => 'setup.py', - 'template' => 'python/setup.py.twig', + 'scope' => 'default', + 'destination' => 'setup.py', + 'template' => 'python/setup.py.twig', ], [ - 'scope' => 'default', - 'destination' => 'setup.cfg', - 'template' => 'python/setup.cfg.twig', + 'scope' => 'default', + 'destination' => 'setup.cfg', + 'template' => 'python/setup.cfg.twig', ], [ - 'scope' => 'default', - 'destination' => 'requirements.txt', - 'template' => 'python/requirements.txt.twig', + 'scope' => 'default', + 'destination' => 'requirements.txt', + 'template' => 'python/requirements.txt.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/__init__.py', - 'template' => 'python/package/__init__.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/__init__.py', + 'template' => 'python/package/__init__.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/client.py', - 'template' => 'python/package/client.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/client.py', + 'template' => 'python/package/client.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/permission.py', - 'template' => 'python/package/permission.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/permission.py', + 'template' => 'python/package/permission.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/role.py', - 'template' => 'python/package/role.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/role.py', + 'template' => 'python/package/role.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/id.py', - 'template' => 'python/package/id.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/id.py', + 'template' => 'python/package/id.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/query.py', - 'template' => 'python/package/query.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/query.py', + 'template' => 'python/package/query.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/exception.py', - 'template' => 'python/package/exception.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/exception.py', + 'template' => 'python/package/exception.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/input_file.py', - 'template' => 'python/package/input_file.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/input_file.py', + 'template' => 'python/package/input_file.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/service.py', - 'template' => 'python/package/service.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/service.py', + 'template' => 'python/package/service.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/services/__init__.py', - 'template' => 'python/package/services/__init__.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/services/__init__.py', + 'template' => 'python/package/services/__init__.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/encoders/__init__.py', - 'template' => 'python/package/services/__init__.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/encoders/__init__.py', + 'template' => 'python/package/services/__init__.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/enums/__init__.py', - 'template' => 'python/package/services/__init__.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/enums/__init__.py', + 'template' => 'python/package/services/__init__.py.twig', ], [ - 'scope' => 'default', - 'destination' => '{{ spec.title | caseSnake}}/encoders/value_class_encoder.py', - 'template' => 'python/package/encoders/value_class_encoder.py.twig', + 'scope' => 'default', + 'destination' => '{{ spec.title | caseSnake}}/encoders/value_class_encoder.py', + 'template' => 'python/package/encoders/value_class_encoder.py.twig', ], [ - 'scope' => 'service', - 'destination' => '{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.py', - 'template' => 'python/package/services/service.py.twig', + 'scope' => 'service', + 'destination' => '{{ spec.title | caseSnake}}/services/{{service.name | caseSnake}}.py', + 'template' => 'python/package/services/service.py.twig', ], [ - 'scope' => 'method', - 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', - 'template' => 'python/docs/example.md.twig', + 'scope' => 'method', + 'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md', + 'template' => 'python/docs/example.md.twig', ], [ - 'scope' => 'default', - 'destination' => '.travis.yml', - 'template' => 'python/.travis.yml.twig', + 'scope' => 'default', + 'destination' => '.travis.yml', + 'template' => 'python/.travis.yml.twig', ], [ - 'scope' => 'enum', - 'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py', - 'template' => 'python/package/enums/enum.py.twig', + 'scope' => 'enum', + 'destination' => '{{ spec.title | caseSnake}}/enums/{{ enum.name | caseSnake }}.py', + 'template' => 'python/package/enums/enum.py.twig', ], ]; } @@ -238,9 +239,9 @@ public function getTypeName(array $parameter, array $spec = []): string */ public function getParamDefault(array $param): string { - $type = $param['type'] ?? ''; - $default = $param['default'] ?? ''; - $required = $param['required'] ?? ''; + $type = $param['type'] ?? ''; + $default = $param['default'] ?? ''; + $required = $param['required'] ?? ''; if ($required) { return ''; @@ -295,8 +296,8 @@ public function getParamDefault(array $param): string */ public function getParamExample(array $param): string { - $type = $param['type'] ?? ''; - $example = $param['example'] ?? ''; + $type = $param['type'] ?? ''; + $example = $param['example'] ?? ''; $output = ''; @@ -342,4 +343,13 @@ public function getParamExample(array $param): string return $output; } + + public function getFilters(): array + { + return [ + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toUpperSnakeCase($value); + }), + ]; + } } diff --git a/src/SDK/Language/Ruby.php b/src/SDK/Language/Ruby.php index 38112cac6..04f4869a7 100644 --- a/src/SDK/Language/Ruby.php +++ b/src/SDK/Language/Ruby.php @@ -352,7 +352,10 @@ public function getFilters(): array $value[$key] = " # " . wordwrap($line, 75, "\n # "); } return implode("\n", $value); - }, ['is_safe' => ['html']]) + }, ['is_safe' => ['html']]), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toUpperSnakeCase($value); + }), ]; } } diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index 02d8290d8..ab69c9808 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -87,6 +87,7 @@ public function getKeywords(): array "unowned", "weak", "willSet", + "Type" ]; } @@ -466,6 +467,9 @@ public function getFilters(): array } return $value; }), + new TwigFilter('caseEnumKey', function (string $value) { + return $this->toCamelCase($value); + }), ]; } @@ -486,7 +490,7 @@ protected function getReturnType(array $method, array $spec, string $generic): s return 'Any'; } - $ret = $this->toUpperCaseWords($method['responseModel']); + $ret = $this->toPascalCase($method['responseModel']); if ($this->hasGenericType($method['responseModel'], $spec)) { $ret .= '<' . $generic . '>'; @@ -498,15 +502,15 @@ protected function getReturnType(array $method, array $spec, string $generic): s protected function getModelType(array $definition, array $spec, string $generic): string { if ($this->hasGenericType($definition['name'], $spec)) { - return $this->toUpperCaseWords($definition['name']) . '<' . $generic . '>'; + return $this->toPascalCase($definition['name']) . '<' . $generic . '>'; } - return $this->toUpperCaseWords($definition['name']); + return $this->toPascalCase($definition['name']); } protected function getPropertyType(array $property, array $spec, string $generic): string { if (\array_key_exists('sub_schema', $property)) { - $type = $this->toUpperCaseWords($property['sub_schema']); + $type = $this->toPascalCase($property['sub_schema']); if ($this->hasGenericType($property['sub_schema'], $spec)) { $type .= '<' . $generic . '>'; diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 129461921..7b558f6c7 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -219,7 +219,7 @@ public function getTypeName(array $parameter, array $method = []): string protected function populateGenerics(string $model, array $spec, array &$generics, bool $skipFirst = false) { if (!$skipFirst && $spec['definitions'][$model]['additionalProperties']) { - $generics[] = $this->toUpperCaseWords($model); + $generics[] = $this->toPascalCase($model); } $properties = $spec['definitions'][$model]['properties']; @@ -268,14 +268,14 @@ public function getReturn(array $method, array $spec): string $ret .= 'Models.'; } - $ret .= $this->toUpperCaseWords($method['responseModel']); + $ret .= $this->toPascalCase($method['responseModel']); $models = []; $this->populateGenerics($method['responseModel'], $spec, $models); $models = array_unique($models); - $models = array_filter($models, fn ($model) => $model != $this->toUpperCaseWords($method['responseModel'])); + $models = array_filter($models, fn ($model) => $model != $this->toPascalCase($method['responseModel'])); if (!empty($models)) { $ret .= '<' . implode(', ', $models) . '>'; @@ -295,9 +295,9 @@ public function getSubSchema(array $property, array $spec): string $generics = []; $this->populateGenerics($property['sub_schema'], $spec, $generics); - $generics = array_filter($generics, fn ($model) => $model != $this->toUpperCaseWords($property['sub_schema'])); + $generics = array_filter($generics, fn ($model) => $model != $this->toPascalCase($property['sub_schema'])); - $ret .= $this->toUpperCaseWords($property['sub_schema']); + $ret .= $this->toPascalCase($property['sub_schema']); if (!empty($generics)) { $ret .= '<' . implode(', ', $generics) . '>'; } @@ -340,6 +340,9 @@ public function getFilters(): array } return implode("\n", $value); }, ['is_safe' => ['html']]), + new TwigFilter('caseEnumKey', function($value) { + return $this->toPascalCase($value); + }), ]; } } diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index d8794f2a4..e30450283 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -191,12 +191,6 @@ public function __construct(Language $language, Spec $spec) } return $value; })); - $this->twig->addFilter(new TwigFilter('strip', function ($value) { - $value = \str_replace(['-',' ',], '_', $value); - $value = \preg_replace('/[^A-Za-z0-9_]/', '', $value); - - return $value; - })); } /** diff --git a/templates/android/docs/java/example.md.twig b/templates/android/docs/java/example.md.twig index 710cc6dcd..d63bf4f25 100644 --- a/templates/android/docs/java/example.md.twig +++ b/templates/android/docs/java/example.md.twig @@ -4,18 +4,36 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback; import {{ sdk.namespace | caseDot }}.models.InputFile; {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}; -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} -{% endif %}{% endfor %} +{% set added = [] %} +{% for method in service.methods %} + +{% for parameter in method.parameters.all %} +{% if parameter.required %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }}; +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} +{% endfor %} Client client = new Client(context) -{% if method.auth|length > 0 %} + {%~ if method.auth|length > 0 %} .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint -{% for node in method.auth %} -{% for key,header in node|keys %} - .set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}"){% if loop.last %};{% endif %} // {{node[header].description}} -{% endfor %}{% endfor %}{% endif %} + {%~ for node in method.auth %} + {%~ for key,header in node|keys %} + .set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}"){% if loop.last %};{% endif %} // {{ node[header].description }} + {%~ endfor %} + {%~ endfor %} + {%~ endif %} {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client); @@ -26,14 +44,22 @@ Client client = new Client(context) } Log.d("Appwrite", result.toString()); -}));{% endif %} +%}));{% endif %} {% for parameter in method.parameters.all %} -{% if parameter.required %} - {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} - -{% endif %} -{% if loop.last %} + {%~ if parameter.required -%} + {%~ if parameter.enumValues is not empty -%} + {%~ if parameter.enumName is not empty -%} + {%~ set name = parameter.enumName -%} + {%~ else -%} + {%~ set name = parameter.name -%} + {%~ endif %} + {{ name }}.{{ parameter.enumValues[0] | caseEnumKey }}, + {%~ else %} + {{ parameter | paramExample }}, + {%~ endif -%} + {%~ endif -%} + {%~ if loop.last %} new CoroutineCallback<>((result, error) -> { if (error != null) { error.printStackTrace(); @@ -43,5 +69,5 @@ Client client = new Client(context) Log.d("Appwrite", result.toString()); }) ); -{% endif %} +{%- endif %} {% endfor %} \ No newline at end of file diff --git a/templates/android/docs/kotlin/example.md.twig b/templates/android/docs/kotlin/example.md.twig index 2b0c44439..09f069f9f 100644 --- a/templates/android/docs/kotlin/example.md.twig +++ b/templates/android/docs/kotlin/example.md.twig @@ -3,29 +3,54 @@ import {{ sdk.namespace | caseDot }}.Client import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}}{% endif %} -{% endif %}{% endfor %} +{% set added = [] %} +{% for method in service.methods %} +{% for parameter in method.parameters.all %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }} +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endfor %} +{% endfor %} val client = Client(context) -{% if method.auth|length > 0 %} + {%~ if method.auth|length > 0 %} .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint -{% for node in method.auth %} -{% for key,header in node|keys %} + {%~ for node in method.auth %} + {%~ for key,header in node|keys %} .set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}} -{% endfor %}{% endfor %}{% endif %} + {%~ endfor %} + {%~ endfor %} + {%~ endif %} val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) -{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}val result = {% else %}val response = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %} +{% if method.type == 'webAuth' %} +{% elseif method.type == 'location' %} +val result = {%~ else %}val response = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %} {% for parameter in method.parameters.all %} -{% if parameter.required %} - {{parameter.name}} = {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} - -{% endif %} -{% if loop.last %} + {%~ if parameter.required -%} + {%~ if parameter.enumValues is not empty -%} + {%~ if parameter.enumName is not empty -%} + {%~ set name = parameter.enumName -%} + {%~ else -%} + {%~ set name = parameter.name -%} + {%~ endif %} + {{ parameter.name }} = {{ name }}.{{ parameter.enumValues[0] | caseEnumKey }}, + {%~ else %} + {{ parameter.name }} = {{ parameter | paramExample }}, + {%~ endif -%} + {%~ endif %} + {%~ if loop.last %} ) -{% endif %} +{%- endif %} {% endfor %} \ No newline at end of file diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index c4adaa651..568cb611c 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | strip }}("{{value}}"){% if not loop.last %},{%else %};{% endif %} + {{ key | caseEnumKey }}("{{value}}"){% if not loop.last %},{%else %};{% endif %} {% endfor %} diff --git a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig index 02e42caf7..21628b501 100644 --- a/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig @@ -60,7 +60,7 @@ class {{ service.name | caseUcfirst }} : Service { ){% if method.type != "webAuth" %}: {{ method | returnType(spec, sdk.namespace | caseDot) | raw }}{% endif %} { val apiPath = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumName is not null %}.value{% endif %}) + .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumValues is not empty %}.value{% endif %}) {%~ endfor %} val apiParams = mutableMapOf( diff --git a/templates/dart/docs/example.md.twig b/templates/dart/docs/example.md.twig index b0f129138..2daced986 100644 --- a/templates/dart/docs/example.md.twig +++ b/templates/dart/docs/example.md.twig @@ -22,7 +22,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else%}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseCamel | replace({'-': ''}) }}{% else %}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); diff --git a/templates/dart/lib/src/enums/enum.dart.twig b/templates/dart/lib/src/enums/enum.dart.twig index d75f958d6..10ab94833 100644 --- a/templates/dart/lib/src/enums/enum.dart.twig +++ b/templates/dart/lib/src/enums/enum.dart.twig @@ -3,7 +3,7 @@ part of {{ language.params.packageName }}.enums; enum {{ enum.name | caseUcfirst | overrideIdentifier }} { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseCamel | replace({'-': ''})}}(value: '{{ value }}'){% if not loop.last %},{% else %};{% endif %} + {{ key | caseEnumKey }}(value: '{{ value }}'){% if not loop.last %},{% else %};{% endif %} {%~ endfor %} diff --git a/templates/deno/docs/example.md.twig b/templates/deno/docs/example.md.twig index e78c1fbf6..002fbafc9 100644 --- a/templates/deno/docs/example.md.twig +++ b/templates/deno/docs/example.md.twig @@ -19,7 +19,7 @@ client {% endif %} -let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); +let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/dotnet/base/params.twig b/templates/dotnet/base/params.twig index d465fa8e6..482ae36ed 100644 --- a/templates/dotnet/base/params.twig +++ b/templates/dotnet/base/params.twig @@ -1,6 +1,6 @@ {% import 'dotnet/base/utils.twig' as utils %} {%~ for parameter in method.parameters.path %} - .Replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel | escapeKeyword }}{% if parameter.enumName is not null %}.Value{% endif %}){% if loop.last %};{% endif %} + .Replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel | escapeKeyword }}{% if parameter.enumValues is not empty %}.Value{% endif %}){% if loop.last %};{% endif %} {%~ endfor %} diff --git a/templates/dotnet/docs/example.md.twig b/templates/dotnet/docs/example.md.twig index d6c1208e4..2ef8db640 100644 --- a/templates/dotnet/docs/example.md.twig +++ b/templates/dotnet/docs/example.md.twig @@ -18,4 +18,4 @@ var {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client {% if method.method != 'delete' %}{% if method.type == 'location' %}byte[]{% else %}{{ method.responseModel | caseUcfirst | overrideIdentifier }}{% endif %} result = {% endif %}await {{ service.name | caseCamel }}.{{ method.name | caseUcfirst }}({% if method.parameters.all | length == 0 %});{% endif %} {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %},{% endif %} - {{ parameter.name }}: {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} diff --git a/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig index 1e8721f88..975947de9 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig @@ -13,7 +13,7 @@ namespace {{ spec.title | caseUcfirst }}.Enums {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static {{ enum.name | caseUcfirst | overrideIdentifier }} {{ key | caseUcfirst | strip }} => new {{ enum.name | caseUcfirst | overrideIdentifier }}("{{ value }}"); + public static {{ enum.name | caseUcfirst | overrideIdentifier }} {{ key | caseEnumKey }} => new {{ enum.name | caseUcfirst | overrideIdentifier }}("{{ value }}"); {%~ endfor %} } } diff --git a/templates/flutter/docs/example.md.twig b/templates/flutter/docs/example.md.twig index fe0c3d629..c7b79e7c8 100644 --- a/templates/flutter/docs/example.md.twig +++ b/templates/flutter/docs/example.md.twig @@ -23,7 +23,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}).then((bytes) { final file = File('path_to_file/filename.ext'); @@ -40,7 +40,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %} ), //works for both public file and private file, for private files you need to be logged in @@ -58,7 +58,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); diff --git a/templates/kotlin/docs/java/example.md.twig b/templates/kotlin/docs/java/example.md.twig index d597795bb..b90130817 100644 --- a/templates/kotlin/docs/java/example.md.twig +++ b/templates/kotlin/docs/java/example.md.twig @@ -30,7 +30,7 @@ Client client = new Client() {% for parameter in method.parameters.all %} {% if parameter.required %} - {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ':''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} + {% if parameter.enumValues | length > 0%} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index 16e8d525f..f59ecd2d0 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -22,7 +22,7 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) {% for parameter in method.parameters.all %} {% if parameter.required %} - {{parameter.name}} = {% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} + {{parameter.name}} = {% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig index a1af9caea..920642a54 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | strip }}("{{value}}"){% if not loop.last %},{% else %};{% endif %} + {{ key | caseEnumKey }}("{{value}}"){% if not loop.last %},{% else %};{% endif %} {% endfor %} diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig index bb9949ecc..d87f79faa 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig @@ -56,7 +56,7 @@ class {{ service.name | caseUcfirst }} : Service { ): {{ method | returnType(spec, sdk.namespace | caseDot) | raw }} { val apiPath = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumName is not null %}.value{% endif %}) + .replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}{% if parameter.enumValues is not empty %}.value{% endif %}) {%~ endfor %} val apiParams = mutableMapOf( diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index ab296d8da..d82adc790 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -24,4 +24,4 @@ $client {% endif %} ${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); -$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); \ No newline at end of file +$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); \ No newline at end of file diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index c3c156318..c9614747a 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,8 +6,8 @@ use JsonSerializable; class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { - {%~ for value in enum.enum %} - private static {{ enum.name | caseUcfirst }} ${{ value | caseSnake | caseUpper | strip }}; + {%~ for key in enum.enum %} + private static {{ enum.name | caseUcfirst }} ${{ key | caseEnumKey }}; {%~ endfor %} private string $value; @@ -31,10 +31,10 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializ {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} public static function {{ key | caseSnake | caseUpper }}(): {{ enum.name | caseUcfirst | overrideIdentifier}} { - if (!isset(self::${{ key | caseUpper | strip }})) { - self::${{ key | caseSnake | caseUpper | strip }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); + if (!isset(self::${{ key | caseEnumKey }})) { + self::${{ key | caseEnumKey }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); } - return self::${{ key | caseSnake | caseUpper | strip }}; + return self::${{ key | caseEnumKey }}; } {% endfor %} } \ No newline at end of file diff --git a/templates/python/docs/example.md.twig b/templates/python/docs/example.md.twig index b3394e4c1..02baf907a 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -21,4 +21,4 @@ client = Client() {% endif %} {{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) -result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUpper | replace({'-': '',' ': '_'}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) +result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{( parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) diff --git a/templates/ruby/lib/container.rb.twig b/templates/ruby/lib/container.rb.twig index 688d54357..7675b688c 100644 --- a/templates/ruby/lib/container.rb.twig +++ b/templates/ruby/lib/container.rb.twig @@ -16,6 +16,10 @@ require_relative '{{ spec.title | caseSnake }}/id' require_relative '{{ spec.title | caseSnake }}/models/{{ defintion.name | caseSnake }}' {% endfor %} +{% for enum in spec.enums %} +require_relative '{{ spec.title | caseSnake }}/enums/{{ enum | caseSnake }}' +{% endfor %} + {% for service in spec.services %} require_relative '{{ spec.title | caseSnake }}/services/{{ service.name | caseSnake }}' {% endfor %} \ No newline at end of file diff --git a/templates/ruby/lib/container/client.rb.twig b/templates/ruby/lib/container/client.rb.twig index 4b4892889..b4b964c87 100644 --- a/templates/ruby/lib/container/client.rb.twig +++ b/templates/ruby/lib/container/client.rb.twig @@ -170,7 +170,7 @@ module {{ spec.title | caseUcfirst }} offset += @chunk_size if defined? result['$id'] - headers['x-{{ spec.title }}-id'] = result['$id'] + headers['x-{{ spec.title | caseLower }}-id'] = result['$id'] end on_progress.call({ @@ -218,6 +218,9 @@ module {{ spec.title | caseUcfirst }} end end + puts @http.inspect + puts "Request: #{method} #{uri.request_uri} #{headers} #{payload}" + begin response = @http.send_request(method, uri.request_uri, payload, headers) rescue => error diff --git a/templates/ruby/lib/container/enums/enum.rb.twig b/templates/ruby/lib/container/enums/enum.rb.twig index 7c6dcce34..c640146e4 100644 --- a/templates/ruby/lib/container/enums/enum.rb.twig +++ b/templates/ruby/lib/container/enums/enum.rb.twig @@ -1,8 +1,10 @@ module {{ spec.title | caseUcfirst }} - module {{ enum.name | caseUcfirst | overrideIdentifier }} -{% for value in enum.enum %} -{% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseUpper | replace({'-': '', ' ':'_', '(': '', ')': '', '.': ''})}} = '{{ value }}' -{% endfor %} + module Enums + module {{ enum.name | caseUcfirst | overrideIdentifier }} + {%~ for value in enum.enum %} + {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} + {{ key | caseUpper | replace({'-': '_', ' ':'_', '(': '', ')': '', '.': ''}) }} = '{{ value }}' + {%~ endfor %} + end end end \ No newline at end of file diff --git a/templates/swift/base/params.twig b/templates/swift/base/params.twig index bb8917e15..1ca566d79 100644 --- a/templates/swift/base/params.twig +++ b/templates/swift/base/params.twig @@ -1,6 +1,6 @@ let apiPath: String = "{{ method.path }}" {%~ for parameter in method.parameters.path %} - .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeSwiftKeyword }}{% if parameter.enumName is not null %}.rawValue{% endif %}) + .replacingOccurrences(of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", with: {{ parameter.name | caseCamel | escapeSwiftKeyword }}{% if parameter.enumValues is not empty %}.rawValue{% endif %}) {%~ endfor %} {%~ if method.parameters.query | merge(method.parameters.body) | length <= 0 %} diff --git a/templates/swift/base/requests/api.twig b/templates/swift/base/requests/api.twig index e93264245..9c3a7b10f 100644 --- a/templates/swift/base/requests/api.twig +++ b/templates/swift/base/requests/api.twig @@ -4,5 +4,5 @@ headers: apiHeaders, params: apiParams{% if method.responseModel %}, converter: converter -{% endif %} + {%~ endif %} ) \ No newline at end of file diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index fef8fe0d4..fe81a9339 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -20,7 +20,7 @@ let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% i let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} {% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} - {{parameter.name}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} {% if loop.last %} ) diff --git a/templates/web/docs/example.md.twig b/templates/web/docs/example.md.twig index ff1bc6f2c..40dd3b4fa 100644 --- a/templates/web/docs/example.md.twig +++ b/templates/web/docs/example.md.twig @@ -16,7 +16,7 @@ client {% endif %} {% if method.type == 'webAuth' %}// Go to OAuth provider login page {% endif %} -{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseUcfirst | replace({'-': ''}) }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); +{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); {% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}console.log(result); // Resource URL{% else %}promise.then(function (response) { console.log(response); // Success From 1c86293b44426118bc6cd3a506573879ade1af43 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 20:24:37 +1300 Subject: [PATCH 77/98] Fix lint --- src/SDK/Language/Web.php | 4 ++-- tests/languages/apple/Tests.swift | 3 ++- tests/languages/ruby/tests.rb | 9 ++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 7b558f6c7..e29d0d0f1 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -340,8 +340,8 @@ public function getFilters(): array } return implode("\n", $value); }, ['is_safe' => ['html']]), - new TwigFilter('caseEnumKey', function($value) { - return $this->toPascalCase($value); + new TwigFilter('caseEnumKey', function ($value) { + return $this->toPascalCase($value); }), ]; } diff --git a/tests/languages/apple/Tests.swift b/tests/languages/apple/Tests.swift index fc0abaac5..0eb75a1aa 100644 --- a/tests/languages/apple/Tests.swift +++ b/tests/languages/apple/Tests.swift @@ -4,6 +4,7 @@ import Foundation import FoundationNetworking #endif import Appwrite +import AppwriteEnums import AsyncHTTPClient import NIO @@ -114,7 +115,7 @@ class Tests: XCTestCase { print(error.localizedDescription) } - mock = try await general.enum(.first) + mock = try await general.xenum(mockType: .first) print(mock.result) do { diff --git a/tests/languages/ruby/tests.rb b/tests/languages/ruby/tests.rb index 35a6ebc2e..d3ab6a52b 100644 --- a/tests/languages/ruby/tests.rb +++ b/tests/languages/ruby/tests.rb @@ -2,10 +2,9 @@ include Appwrite -client = Client.new -client - .add_header('Origin', 'http://localhost') - .set_self_signed() +client = Client.new() + .add_header('Origin', 'http://localhost') + .set_self_signed() foo = Foo.new(client) bar = Bar.new(client) @@ -83,7 +82,7 @@ puts e end -response = general.enum(MockType::FIRST) +response = general.enum(mockType: MockType::FIRST) puts response.result begin From 9439633bb894d3bb435573f9b7cabd899e46a28d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 20:51:38 +1300 Subject: [PATCH 78/98] Fix PHP enum key case filter --- src/SDK/Language/PHP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index 80e2f6737..f37383848 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -390,7 +390,7 @@ public function getFilters(): array return php_uname('s') . '; ' . php_uname('v') . '; ' . php_uname('m'); }), new TwigFilter('caseEnumKey', function (string $value) { - $this->toUpperSnakeCase($value); + return $this->toUpperSnakeCase($value); }), ]; } From fe9b52377ca6d82784f229be826c53707dc7e464 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 20:59:10 +1300 Subject: [PATCH 79/98] Fix Python docs template syntax error --- templates/python/docs/example.md.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/python/docs/example.md.twig b/templates/python/docs/example.md.twig index 02baf907a..8063e63bd 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -21,4 +21,4 @@ client = Client() {% endif %} {{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) -result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{( parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) +result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) From d37a6fc0192025aeb126f9c861c87f48cbe7edcb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 21:03:27 +1300 Subject: [PATCH 80/98] Add missing file for flutter --- src/SDK/Language/Flutter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/SDK/Language/Flutter.php b/src/SDK/Language/Flutter.php index 1da9709b5..77f5c66bf 100644 --- a/src/SDK/Language/Flutter.php +++ b/src/SDK/Language/Flutter.php @@ -60,6 +60,11 @@ public function getFiles(): array 'destination' => '/lib/models.dart', 'template' => 'dart/lib/models.dart.twig', ], + [ + 'scope' => 'default', + 'destination' => '/lib/enums.dart', + 'template' => 'dart/lib/enums.dart.twig', + ], [ 'scope' => 'default', 'destination' => '/lib/permission.dart', From 7936e6a4a64c86cab9bfee04061584c890ddb0c1 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 21:18:53 +1300 Subject: [PATCH 81/98] Fix flutter missing import --- templates/flutter/lib/package.dart.twig | 1 + tests/languages/flutter/tests.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/flutter/lib/package.dart.twig b/templates/flutter/lib/package.dart.twig index 6b1d38848..48493400b 100644 --- a/templates/flutter/lib/package.dart.twig +++ b/templates/flutter/lib/package.dart.twig @@ -11,6 +11,7 @@ import 'src/enums.dart'; import 'src/service.dart'; import 'src/input_file.dart'; import 'models.dart' as models; +import 'enums.dart' as enums; import 'src/upload_progress.dart'; export 'src/response.dart'; diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index 56a0e9ba1..fe6fd653c 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -21,7 +21,7 @@ void main() async { PathProviderPlatform.instance = FakePathProvider(); Client client = Client() .addHeader("Origin", "http://localhost") - .setSelfSigned(true); + .setSelfSigned(); Foo foo = Foo(client); Bar bar = Bar(client); General general = General(client); From 321c9f45bc132a003a313c891796dbac19119e40 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 21:24:27 +1300 Subject: [PATCH 82/98] Fix go tests --- src/SDK/Language/Go.php | 6 ------ tests/Go112Test.php | 2 +- tests/Go118Test.php | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/SDK/Language/Go.php b/src/SDK/Language/Go.php index 9ab699d37..07c1f3e2b 100644 --- a/src/SDK/Language/Go.php +++ b/src/SDK/Language/Go.php @@ -108,12 +108,6 @@ public function getFiles(): array */ public function getTypeName(array $parameter, array $spec = []): string { - if (isset($parameter['enumName'])) { - return \ucfirst($parameter['enumName']); - } - if (!empty($parameter['enumValues'])) { - return \ucfirst($parameter['name']); - } return match ($parameter['type']) { self::TYPE_INTEGER => 'int', self::TYPE_NUMBER => 'float64', diff --git a/tests/Go112Test.php b/tests/Go112Test.php index a5beb1f6b..6b5979799 100644 --- a/tests/Go112Test.php +++ b/tests/Go112Test.php @@ -17,12 +17,12 @@ class Go112Test extends Base ]; protected string $command = 'docker run --rm -v $(pwd):/app -w /app golang:1.12 sh -c "cd tests/languages/go/ && ./test.sh"'; + protected array $expectedOutput = [ ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, ...Base::DOWNLOAD_RESPONSES, - ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ]; } diff --git a/tests/Go118Test.php b/tests/Go118Test.php index 4117e0265..b1cf97f6f 100644 --- a/tests/Go118Test.php +++ b/tests/Go118Test.php @@ -17,12 +17,12 @@ class Go118Test extends Base ]; protected string $command = 'docker run --rm -v $(pwd):/app -w /app golang:1.18 sh -c "cd tests/languages/go/ && ./test.sh"'; + protected array $expectedOutput = [ ...Base::FOO_RESPONSES, ...Base::BAR_RESPONSES, ...Base::GENERAL_RESPONSES, ...Base::DOWNLOAD_RESPONSES, - ...Base::ENUM_RESPONSES, ...Base::EXCEPTION_RESPONSES, ]; } From 1d6fc0cdb8244748fe691aca7ca33b26853c224a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 22:15:32 +1300 Subject: [PATCH 83/98] Fix swift + apple tests --- tests/languages/apple/Tests.swift | 10 +++++----- tests/languages/swift/Tests.swift | 14 +++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/languages/apple/Tests.swift b/tests/languages/apple/Tests.swift index 0eb75a1aa..4d3fbe729 100644 --- a/tests/languages/apple/Tests.swift +++ b/tests/languages/apple/Tests.swift @@ -59,19 +59,19 @@ class Tests: XCTestCase { // Bar Tests - mock = try await bar.get(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.get(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.post(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.post(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.put(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.put(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.patch(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.patch(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.delete(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.delete(required: "string", default: 123, z: ["string in array"]) print(mock.result) diff --git a/tests/languages/swift/Tests.swift b/tests/languages/swift/Tests.swift index 3268c188c..3662697a4 100644 --- a/tests/languages/swift/Tests.swift +++ b/tests/languages/swift/Tests.swift @@ -19,6 +19,7 @@ class Tests: XCTestCase { } func test() async throws { + do { let client = Client() .setProject("console") .addHeader(key: "Origin", value: "http://localhost") @@ -48,19 +49,19 @@ class Tests: XCTestCase { // Bar Tests - mock = try await bar.get(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.get(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.post(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.post(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.put(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.put(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.patch(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.patch(required: "string", default: 123, z: ["string in array"]) print(mock.result) - mock = try await bar.delete(xrequired: "string", xdefault: 123, z: ["string in array"]) + mock = try await bar.delete(required: "string", default: 123, z: ["string in array"]) print(mock.result) @@ -167,5 +168,8 @@ class Tests: XCTestCase { mock = try await general.headers() print(mock.result) + } catch { + print(error.localizedDescription) + } } } From 39410e005e1eaf4069a1db6bfb0e3c0c580c51b3 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 22:17:53 +1300 Subject: [PATCH 84/98] Fix flutter test enum casing --- tests/languages/flutter/tests.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index fe6fd653c..92257f5b3 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -102,7 +102,7 @@ void main() async { response = await general.upload(x: 'string', y: 123, z: ['string in array'], file: file); print(response.result); - response = await general.xenum(mockType: MockType.FIRST); + response = await general.xenum(mockType: MockType.first); print(response.result); try { From d11c78aed72d9cbc5286c0b191860a4134877234 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 22:32:16 +1300 Subject: [PATCH 85/98] Remove invalid flutter package entries --- templates/flutter/lib/package.dart.twig | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/flutter/lib/package.dart.twig b/templates/flutter/lib/package.dart.twig index 48493400b..919d34d5c 100644 --- a/templates/flutter/lib/package.dart.twig +++ b/templates/flutter/lib/package.dart.twig @@ -29,7 +29,4 @@ part 'role.dart'; part 'id.dart'; {% for service in spec.services %} part 'services/{{service.name | caseDash}}.dart'; -{% endfor %} -{% for enum in spec.enums %} -part 'src/enums/{{enum | caseSnake}}.dart'; {% endfor %} \ No newline at end of file From 530c44f48c0e75234f1be10d341581ee0a36bef9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 23:09:00 +1300 Subject: [PATCH 86/98] Fix chromium tests --- tests/languages/web/index.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/languages/web/index.html b/tests/languages/web/index.html index f277a4551..e8ef6bf85 100644 --- a/tests/languages/web/index.html +++ b/tests/languages/web/index.html @@ -21,9 +21,7 @@ let responseRealtime = 'Realtime failed!'; // Init SDK const { Client, Foo, Bar, General, Query, Permission, Role, ID, MockType } = Appwrite; - const client = new Client() - .addHeader("Origin", "http://localhost") - .setSelfSigned(true); + const client = new Client(); const foo = new Foo(client); const bar = new Bar(client); From f6dc423b96cc1b97ba92403d4bac31c21dda713a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 27 Oct 2023 23:09:45 +1300 Subject: [PATCH 87/98] Fix ruby tests --- templates/ruby/lib/container/client.rb.twig | 3 --- tests/languages/ruby/tests.rb | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/templates/ruby/lib/container/client.rb.twig b/templates/ruby/lib/container/client.rb.twig index b4b964c87..e99d30c94 100644 --- a/templates/ruby/lib/container/client.rb.twig +++ b/templates/ruby/lib/container/client.rb.twig @@ -218,9 +218,6 @@ module {{ spec.title | caseUcfirst }} end end - puts @http.inspect - puts "Request: #{method} #{uri.request_uri} #{headers} #{payload}" - begin response = @http.send_request(method, uri.request_uri, payload, headers) rescue => error diff --git a/tests/languages/ruby/tests.rb b/tests/languages/ruby/tests.rb index d3ab6a52b..e5a6b0e4b 100644 --- a/tests/languages/ruby/tests.rb +++ b/tests/languages/ruby/tests.rb @@ -1,10 +1,10 @@ require_relative '../../sdks/ruby/lib/appwrite' include Appwrite +include Appwrite::Enums client = Client.new() .add_header('Origin', 'http://localhost') - .set_self_signed() foo = Foo.new(client) bar = Bar.new(client) @@ -82,7 +82,7 @@ puts e end -response = general.enum(mockType: MockType::FIRST) +response = general.enum(mock_type: MockType::FIRST) puts response.result begin From 01cf1a36af5c589505e8f76718c68768e007f9f8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Sat, 28 Oct 2023 00:06:07 +1300 Subject: [PATCH 88/98] Enable flutter realtime tests --- tests/languages/flutter/tests.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/languages/flutter/tests.dart b/tests/languages/flutter/tests.dart index 92257f5b3..4553cab3b 100644 --- a/tests/languages/flutter/tests.dart +++ b/tests/languages/flutter/tests.dart @@ -32,7 +32,7 @@ void main() async { "wss://demo.appwrite.io/v1"); // change this later to appwrite.io Realtime realtime = Realtime(client); - // final rtsub = realtime.subscribe(["tests"]); + final rtsub = realtime.subscribe(["tests"]); await Future.delayed(Duration(seconds: 5)); client.addHeader('Origin', 'http://localhost'); @@ -123,10 +123,10 @@ void main() async { print(e.message); } - // rtsub.stream.listen((message) { - // print(message.payload["response"]); - // rtsub.close(); - // }); + rtsub.stream.listen((message) { + print(message.payload["response"]); + rtsub.close(); + }); await Future.delayed(Duration(seconds: 5)); From 4c28b9613516a848f6f0ac0924a5e6393e7017bd Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 30 Oct 2023 17:34:33 +1300 Subject: [PATCH 89/98] Fix Android enum docs --- templates/android/docs/java/example.md.twig | 12 ++++-------- templates/android/docs/kotlin/example.md.twig | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/templates/android/docs/java/example.md.twig b/templates/android/docs/java/example.md.twig index d63bf4f25..a49b67fbb 100644 --- a/templates/android/docs/java/example.md.twig +++ b/templates/android/docs/java/example.md.twig @@ -4,12 +4,9 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback; import {{ sdk.namespace | caseDot }}.models.InputFile; {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}; - {% set added = [] %} -{% for method in service.methods %} - {% for parameter in method.parameters.all %} -{% if parameter.required %} +{% if method == parameter.required %} {% if parameter.enumValues is not empty %} {% if parameter.enumName is not empty %} {% set name = parameter.enumName %} @@ -23,7 +20,6 @@ import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }}; {% endif %} {% endif %} {% endfor %} -{% endfor %} Client client = new Client(context) {%~ if method.auth|length > 0 %} @@ -38,13 +34,13 @@ Client client = new Client(context) {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client); {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}new CoroutineCallback<>((result, error) -> { - if (error != null) + if (error != null) { error.printStackTrace(); return; } Log.d("Appwrite", result.toString()); -%}));{% endif %} +}));{% endif %} {% for parameter in method.parameters.all %} {%~ if parameter.required -%} @@ -54,7 +50,7 @@ Client client = new Client(context) {%~ else -%} {%~ set name = parameter.name -%} {%~ endif %} - {{ name }}.{{ parameter.enumValues[0] | caseEnumKey }}, + {{ name }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}, {%~ else %} {{ parameter | paramExample }}, {%~ endif -%} diff --git a/templates/android/docs/kotlin/example.md.twig b/templates/android/docs/kotlin/example.md.twig index 09f069f9f..175ef8038 100644 --- a/templates/android/docs/kotlin/example.md.twig +++ b/templates/android/docs/kotlin/example.md.twig @@ -1,12 +1,12 @@ import {{ sdk.namespace | caseDot }}.Client +import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback {% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %} import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} - {% set added = [] %} -{% for method in service.methods %} {% for parameter in method.parameters.all %} +{% if method == parameter.required %} {% if parameter.enumValues is not empty %} {% if parameter.enumName is not empty %} {% set name = parameter.enumName %} @@ -18,7 +18,7 @@ import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }} {% set added = added|merge([name]) %} {% endif %} {% endif %} -{% endfor %} +{% endif %} {% endfor %} val client = Client(context) @@ -45,7 +45,7 @@ val result = {%~ else %}val response = {% endif %}{{ service.name | caseCamel }} {%~ else -%} {%~ set name = parameter.name -%} {%~ endif %} - {{ parameter.name }} = {{ name }}.{{ parameter.enumValues[0] | caseEnumKey }}, + {{ parameter.name }} = {{ name }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}, {%~ else %} {{ parameter.name }} = {{ parameter | paramExample }}, {%~ endif -%} From c6b568620a09c138ea82fcddc01880ce07cb3f6e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 30 Oct 2023 17:35:14 +1300 Subject: [PATCH 90/98] Fix docs --- templates/dart/docs/example.md.twig | 2 +- templates/deno/docs/example.md.twig | 2 +- templates/dotnet/docs/example.md.twig | 2 +- templates/flutter/docs/example.md.twig | 6 ++--- templates/kotlin/docs/java/example.md.twig | 22 +++++++++++++---- templates/kotlin/docs/kotlin/example.md.twig | 25 +++++++++++++++----- templates/node/docs/example.md.twig | 4 ++-- templates/php/docs/example.md.twig | 24 ++++++++++++++----- templates/python/docs/example.md.twig | 24 ++++++++++++++----- templates/ruby/docs/example.md.twig | 15 ++++++++++-- templates/swift/docs/example.md.twig | 4 ++-- templates/web/docs/example.md.twig | 2 +- 12 files changed, 96 insertions(+), 36 deletions(-) diff --git a/templates/dart/docs/example.md.twig b/templates/dart/docs/example.md.twig index 2daced986..a8e809dd6 100644 --- a/templates/dart/docs/example.md.twig +++ b/templates/dart/docs/example.md.twig @@ -22,7 +22,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseCamel | replace({'-': ''}) }}{% else %}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}{% else %}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); diff --git a/templates/deno/docs/example.md.twig b/templates/deno/docs/example.md.twig index 002fbafc9..13ac81a3c 100644 --- a/templates/deno/docs/example.md.twig +++ b/templates/deno/docs/example.md.twig @@ -19,7 +19,7 @@ client {% endif %} -let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); +let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/dotnet/docs/example.md.twig b/templates/dotnet/docs/example.md.twig index 2ef8db640..51b6c602c 100644 --- a/templates/dotnet/docs/example.md.twig +++ b/templates/dotnet/docs/example.md.twig @@ -18,4 +18,4 @@ var {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client {% if method.method != 'delete' %}{% if method.type == 'location' %}byte[]{% else %}{{ method.responseModel | caseUcfirst | overrideIdentifier }}{% endif %} result = {% endif %}await {{ service.name | caseCamel }}.{{ method.name | caseUcfirst }}({% if method.parameters.all | length == 0 %});{% endif %} {% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %},{% endif %} - {{ parameter.name }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %} diff --git a/templates/flutter/docs/example.md.twig b/templates/flutter/docs/example.md.twig index c7b79e7c8..8bb04a23a 100644 --- a/templates/flutter/docs/example.md.twig +++ b/templates/flutter/docs/example.md.twig @@ -23,7 +23,7 @@ void main() { // Init SDK {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}).then((bytes) { final file = File('path_to_file/filename.ext'); @@ -40,7 +40,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %} ), //works for both public file and private file, for private files you need to be logged in @@ -58,7 +58,7 @@ FutureBuilder( {% endif %} {% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, + {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %}, {% endif %} {% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); diff --git a/templates/kotlin/docs/java/example.md.twig b/templates/kotlin/docs/java/example.md.twig index b90130817..faef6d972 100644 --- a/templates/kotlin/docs/java/example.md.twig +++ b/templates/kotlin/docs/java/example.md.twig @@ -4,10 +4,22 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback; import {{ sdk.namespace | caseDot }}.models.InputFile; {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}; -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %} - -{% endif %}{% endfor %} +{% set added = [] %} +{% for parameter in method.parameters.all %} +{% if method == parameter.required %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }}; +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} Client client = new Client() {% if method.auth|length > 0 %} @@ -30,7 +42,7 @@ Client client = new Client() {% for parameter in method.parameters.all %} {% if parameter.required %} - {% if parameter.enumValues | length > 0%} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} + {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index f59ecd2d0..c5703ac3d 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -1,14 +1,27 @@ import {{ sdk.namespace | caseDot }}.Client +import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback {% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %} import {{ sdk.namespace | caseDot }}.models.InputFile {% endif %} import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }} -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}}{% endif %} - -{% endif %}{% endfor %} +{% set added = [] %} +{% for parameter in method.parameters.all %} +{% if method == parameter.required %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }} +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} -val client = Client(context) +val client = Client() {% if method.auth|length > 0 %} .setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint {% for node in method.auth %} @@ -22,7 +35,7 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) {% for parameter in method.parameters.all %} {% if parameter.required %} - {{parameter.name}} = {% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} + {{parameter.name}} = {% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %} {% endif %} {% if loop.last %} diff --git a/templates/node/docs/example.md.twig b/templates/node/docs/example.md.twig index db06dbd04..3b79fbb21 100644 --- a/templates/node/docs/example.md.twig +++ b/templates/node/docs/example.md.twig @@ -6,7 +6,7 @@ const fs = require('fs'); // Init SDK const client = new sdk.Client(); -const {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); +const {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client); {% if method.auth|length > 0 %} client @@ -18,7 +18,7 @@ client {% endfor %}; {% endif %} -const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | replace({'-': '',' ': ''}) }}{% else%}{{ parameter | paramExample}}{% endif %}{% endif %}{% endfor %}); +const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}sdk.{{ parameter.enumName }}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample}}{% endif %}{% endif %}{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index d82adc790..8cabc50b3 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -5,10 +5,22 @@ use {{ spec.title | caseUcfirst }}\Client; use {{ spec.title | caseUcfirst }}\InputFile; {% endif %} use {{ spec.title | caseUcfirst }}\Services\{{ service.name | caseUcfirst }}; -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};{% endif %} - -{% endif %}{% endfor %} +{% set added = [] %} +{% for parameter in method.parameters.all %} +{% if method == parameter.required %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}}; +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} $client = new Client(); @@ -22,6 +34,6 @@ $client {% endfor %}; {% endif %} -${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); +${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client); -$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); \ No newline at end of file +$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}::{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}(){% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); \ No newline at end of file diff --git a/templates/python/docs/example.md.twig b/templates/python/docs/example.md.twig index 8063e63bd..88661d97f 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -2,10 +2,22 @@ from {{ spec.title | caseSnake }}.client import Client {% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %} from {{ spec.title | caseSnake }}.input_file import InputFile {% endif %} -from {{ spec.title | caseSnake }}.services.{{ service.name | caseSnake }} import {{ service.name | caseUcfirst }} -{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %} -{% if parameter.enumValues | length > 0%}from {{ spec.title | caseUcfirst }}.enums import {{parameter.enumName | caseUcfirst}},{% endif %} -{% endif %}{% endfor %} +{% set added = [] %} +{% for parameter in method.parameters.all %} +{% if method == parameter.required %} +{% if parameter.enumValues is not empty %} +{% if parameter.enumName is not empty %} +{% set name = parameter.enumName %} +{% else %} +{% set name = parameter.name %} +{% endif %} +{% if name not in added %} +from {{ spec.title | caseUcfirst }}.enums import {{parameter.enumName | caseUcfirst}} +{% set added = added|merge([name]) %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} client = Client() @@ -19,6 +31,6 @@ client = Client() {% endfor %}) {% endif %} -{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) +{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client) -result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) +result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) diff --git a/templates/ruby/docs/example.md.twig b/templates/ruby/docs/example.md.twig index ed2ef5313..560d0c416 100644 --- a/templates/ruby/docs/example.md.twig +++ b/templates/ruby/docs/example.md.twig @@ -1,6 +1,17 @@ require '{{ spec.title }}' include {{ spec.title | caseUcfirst }} +{% set break = false %} +{% for parameter in method.parameters.all %} +{% if not break %} +{% if method == parameter.required %} +{% if parameter.enumValues is not empty %} +include {{ spec.title | caseUcfirst }}::Enums +{% set break = true %} +{% endif %} +{% endif %} +{% endif %} +{% endfor %} client = Client.new .set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint @@ -10,8 +21,8 @@ client = Client.new {% endfor %} {% endfor %} -{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}.new(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{parameter.name | caseSnake}}:{{ parameter | paramExample }}{% endfor %}{% endif %}) +{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}.new(client) -response = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{parameter.name|caseSnake}}: {% if parameter.type == 'file' %}{{ parameter | paramExample }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) +response = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{parameter.name|caseSnake}}: {% if parameter.type == 'file' %}{{ parameter | paramExample }}{% else %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}::{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endif %}{% endfor %}) puts response.inspect \ No newline at end of file diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index fe81a9339..406f68033 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -17,10 +17,10 @@ let client = Client() let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) -let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} +let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}bytes{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} {% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} - {{ parameter.name }}: {% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0 %}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} {% if loop.last %} ) diff --git a/templates/web/docs/example.md.twig b/templates/web/docs/example.md.twig index 40dd3b4fa..df2ef4b41 100644 --- a/templates/web/docs/example.md.twig +++ b/templates/web/docs/example.md.twig @@ -16,7 +16,7 @@ client {% endif %} {% if method.type == 'webAuth' %}// Go to OAuth provider login page {% endif %} -{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); +{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}); {% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}console.log(result); // Resource URL{% else %}promise.then(function (response) { console.log(response); // Success From 3738484274e1c0006898fc6a7d413e3544527744 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 30 Oct 2023 18:34:18 +1300 Subject: [PATCH 91/98] Fix Kotlin enum keys --- src/SDK/Language/Kotlin.php | 4 ++++ .../library/src/main/java/io/appwrite/enums/Enum.kt.twig | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SDK/Language/Kotlin.php b/src/SDK/Language/Kotlin.php index 4b2d89530..bde9513cd 100644 --- a/src/SDK/Language/Kotlin.php +++ b/src/SDK/Language/Kotlin.php @@ -440,6 +440,10 @@ public function getFilters(): array return $this->hasGenericType($model, $spec); }), new TwigFilter('caseEnumKey', function (string $value) { + if (isset($this->getIdentifierOverrides()[$value])) { + $value = $this->getIdentifierOverrides()[$value]; + } + $value = \preg_replace('/[^a-zA-Z0-9]/', '', $value); return $this->toUpperSnakeCase($value); }), ]; diff --git a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig index 568cb611c..920642a54 100644 --- a/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig +++ b/templates/android/library/src/main/java/io/appwrite/enums/Enum.kt.twig @@ -3,7 +3,7 @@ package {{ sdk.namespace | caseDot }}.enums enum class {{ enum.name | caseUcfirst | overrideIdentifier }}(val value: String) { {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - {{ key | caseEnumKey }}("{{value}}"){% if not loop.last %},{%else %};{% endif %} + {{ key | caseEnumKey }}("{{value}}"){% if not loop.last %},{% else %};{% endif %} {% endfor %} From e3cc1f5bbeff1934778020db58d3b7fe68b236a7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 30 Oct 2023 18:34:28 +1300 Subject: [PATCH 92/98] Fix PHP enum keys --- src/SDK/Language/PHP.php | 4 ++++ templates/php/src/Enums/Enum.php.twig | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index f37383848..03ec2305d 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -390,6 +390,10 @@ public function getFilters(): array return php_uname('s') . '; ' . php_uname('v') . '; ' . php_uname('m'); }), new TwigFilter('caseEnumKey', function (string $value) { + if (isset($this->getIdentifierOverrides()[$value])) { + $value = $this->getIdentifierOverrides()[$value]; + } + $value = \preg_replace('/[^a-zA-Z0-9]/', '', $value); return $this->toUpperSnakeCase($value); }), ]; diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index c9614747a..a678b2ac0 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,7 +6,7 @@ use JsonSerializable; class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { - {%~ for key in enum.enum %} + {%~ for key in enum.keys %} private static {{ enum.name | caseUcfirst }} ${{ key | caseEnumKey }}; {%~ endfor %} @@ -29,7 +29,7 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializ {% for value in enum.enum %} {% set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - public static function {{ key | caseSnake | caseUpper }}(): {{ enum.name | caseUcfirst | overrideIdentifier}} + public static function {{ key | caseEnumKey }}(): {{ enum.name | caseUcfirst | overrideIdentifier}} { if (!isset(self::${{ key | caseEnumKey }})) { self::${{ key | caseEnumKey }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); From f7e69b142250d2bdc75b15107fe69237c20d6195 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 30 Oct 2023 18:34:39 +1300 Subject: [PATCH 93/98] Fix swift enum keys --- src/SDK/Language/Swift.php | 4 ++++ templates/swift/Sources/Enums/Enum.swift.twig | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index ab69c9808..e53dfd88d 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -468,6 +468,10 @@ public function getFilters(): array return $value; }), new TwigFilter('caseEnumKey', function (string $value) { + if (isset($this->getIdentifierOverrides()[$value])) { + $value = $this->getIdentifierOverrides()[$value]; + } + $value = \preg_replace('/[^a-zA-Z0-9]/', '', $value); return $this->toCamelCase($value); }), ]; diff --git a/templates/swift/Sources/Enums/Enum.swift.twig b/templates/swift/Sources/Enums/Enum.swift.twig index 98674b1f4..a54c148e1 100644 --- a/templates/swift/Sources/Enums/Enum.swift.twig +++ b/templates/swift/Sources/Enums/Enum.swift.twig @@ -3,7 +3,7 @@ import Foundation public enum {{ enum.name | caseUcfirst | overrideIdentifier }}: String, Codable { {%~ for value in enum.enum %} {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} - case {{ key | caseCamel | replace({'-': ''}) | escapeSwiftKeyword }} + case {{ key | caseEnumKey | escapeSwiftKeyword }} = "{{ value }}" {%~ endfor %} public func encode(to encoder: Encoder) throws { From c921cbbcfb5ef16305c6455fe5ca27fdab75c00a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Nov 2023 17:40:27 +1300 Subject: [PATCH 94/98] Fix PHP --- templates/php/src/Enums/Enum.php.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index a678b2ac0..149275121 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,7 +6,7 @@ use JsonSerializable; class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { - {%~ for key in enum.keys %} + {%~ for key in enum.enum %} private static {{ enum.name | caseUcfirst }} ${{ key | caseEnumKey }}; {%~ endfor %} From 7716e90cc5147ef04512cbb2f886861f04767ff9 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Nov 2023 17:54:20 +1300 Subject: [PATCH 95/98] Fix dotnet formatting --- .../src/Appwrite/Converters/ValueClassConverter.cs.twig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig index d46cc93b8..c437fe0e8 100644 --- a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig +++ b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig @@ -8,7 +8,9 @@ namespace {{ spec.title | caseUcfirst }}.Converters public override bool CanConvert(Type objectType) { - return {% for enum in spec.enums %}typeof({{ enum | caseUcfirst }}).IsAssignableFrom(objectType){% if not loop.last %} ||{% else %};{% endif %} + return + {%~ for enum in spec.enums %} + typeof({{ enum | caseUcfirst }}).IsAssignableFrom(objectType){% if not loop.last %} ||{% else %};{% endif %} {%~ endfor %} } From bf6c43567f1036c2584292777633c1e29e663fb6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Nov 2023 18:17:02 +1300 Subject: [PATCH 96/98] Use base class for dotnet enums to improve converter performance --- src/SDK/Language/DotNet.php | 5 +++++ .../src/Appwrite/Converters/ValueClassConverter.cs.twig | 8 ++------ templates/dotnet/src/Appwrite/Enums/Enum.cs.twig | 2 +- templates/dotnet/src/Appwrite/Enums/IEnum.cs.twig | 9 +++++++++ 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 templates/dotnet/src/Appwrite/Enums/IEnum.cs.twig diff --git a/src/SDK/Language/DotNet.php b/src/SDK/Language/DotNet.php index c077be3f3..0bd9082c7 100644 --- a/src/SDK/Language/DotNet.php +++ b/src/SDK/Language/DotNet.php @@ -402,6 +402,11 @@ public function getFiles(): array 'scope' => 'enum', 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/{{ enum.name | caseUcfirst | overrideIdentifier }}.cs', 'template' => 'dotnet/src/Appwrite/Enums/Enum.cs.twig', + ], + [ + 'scope' => 'default', + 'destination' => '/src/{{ spec.title | caseUcfirst }}/Enums/IEnum.cs', + 'template' => 'dotnet/src/Appwrite/Enums/IEnum.cs.twig', ] ]; } diff --git a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig index c437fe0e8..8c6a46714 100644 --- a/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig +++ b/templates/dotnet/src/Appwrite/Converters/ValueClassConverter.cs.twig @@ -8,11 +8,7 @@ namespace {{ spec.title | caseUcfirst }}.Converters public override bool CanConvert(Type objectType) { - return - {%~ for enum in spec.enums %} - typeof({{ enum | caseUcfirst }}).IsAssignableFrom(objectType){% if not loop.last %} ||{% else %};{% endif %} - - {%~ endfor %} + return typeof(IEnum).IsAssignableFrom(objectType); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) @@ -27,7 +23,7 @@ namespace {{ spec.title | caseUcfirst }}.Converters public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var type = value.GetType(); - var property = type.GetProperty("Value"); + var property = type.GetProperty(nameof(IEnum.Value)); var propertyValue = property.GetValue(value); if (propertyValue == null) diff --git a/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig index 975947de9..6720ce59b 100644 --- a/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig +++ b/templates/dotnet/src/Appwrite/Enums/Enum.cs.twig @@ -2,7 +2,7 @@ using System; namespace {{ spec.title | caseUcfirst }}.Enums { - public class {{ enum.name | caseUcfirst | overrideIdentifier }} + public class {{ enum.name | caseUcfirst | overrideIdentifier }} : IEnum { public string Value { get; private set; } diff --git a/templates/dotnet/src/Appwrite/Enums/IEnum.cs.twig b/templates/dotnet/src/Appwrite/Enums/IEnum.cs.twig new file mode 100644 index 000000000..5d7744d12 --- /dev/null +++ b/templates/dotnet/src/Appwrite/Enums/IEnum.cs.twig @@ -0,0 +1,9 @@ +using System; + +namespace {{ spec.title | caseUcfirst }}.Enums +{ + public interface IEnum + { + public string Value { get; } + } +} From 36b5ffe73021fd7eb2c746c583d2733caee647a7 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Nov 2023 18:23:28 +1300 Subject: [PATCH 97/98] Fix PHP keys --- templates/php/src/Enums/Enum.php.twig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index 149275121..4c13ad041 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -6,7 +6,8 @@ use JsonSerializable; class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializable { - {%~ for key in enum.enum %} + {%~ for value in enum.enum %} + {%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %} private static {{ enum.name | caseUcfirst }} ${{ key | caseEnumKey }}; {%~ endfor %} From 2c7040797f466fa33ed74b112b7426b4c9fff7e6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Nov 2023 18:40:13 +1300 Subject: [PATCH 98/98] Use raw for swift escapes --- src/SDK/Language/Swift.php | 2 +- templates/php/src/Enums/Enum.php.twig | 2 +- templates/swift/docs/example.md.twig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SDK/Language/Swift.php b/src/SDK/Language/Swift.php index e53dfd88d..db69689cd 100644 --- a/src/SDK/Language/Swift.php +++ b/src/SDK/Language/Swift.php @@ -462,7 +462,7 @@ public function getFilters(): array return $this->hasGenericType($model, $spec); }), new TwigFilter('escapeSwiftKeyword', function ($value) { - if (in_array($value, $this->getKeywords())) { + if (\in_array($value, $this->getKeywords())) { return "`{$value}`"; } return $value; diff --git a/templates/php/src/Enums/Enum.php.twig b/templates/php/src/Enums/Enum.php.twig index 4c13ad041..08f74c840 100644 --- a/templates/php/src/Enums/Enum.php.twig +++ b/templates/php/src/Enums/Enum.php.twig @@ -33,7 +33,7 @@ class {{ enum.name | caseUcfirst | overrideIdentifier }} implements JsonSerializ public static function {{ key | caseEnumKey }}(): {{ enum.name | caseUcfirst | overrideIdentifier}} { if (!isset(self::${{ key | caseEnumKey }})) { - self::${{ key | caseEnumKey }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{value}}'); + self::${{ key | caseEnumKey }} = new {{ enum.name | caseUcfirst | overrideIdentifier }}('{{ value }}'); } return self::${{ key | caseEnumKey }}; } diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index 406f68033..72125235d 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -20,7 +20,7 @@ let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% i let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}bytes{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %} {% for parameter in method.parameters.all | filter((parameter) => parameter.required) %} - {{ parameter.name }}: {% if parameter.enumValues | length > 0 %}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %} + {{ parameter.name }}: {% if parameter.enumValues | length > 0 %}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword | raw }}{% endif %}{% if not loop.last %},{% endif %} {% if loop.last %} )