diff --git a/src/SDK/Language/Dart.php b/src/SDK/Language/Dart.php index 9040855fe..b6f24371a 100644 --- a/src/SDK/Language/Dart.php +++ b/src/SDK/Language/Dart.php @@ -440,6 +440,35 @@ public function getFiles() ]; } + public function permissionHelperExample() { + return '[ + Permission.read(Role.any()), + Permission.create(Role.user(ID.custom("6abdzeeq23dfds")), + Permission.delete(Role.team(ID.custom("editors"), "owner")), + ]'; + } + + public function queriesHelperExample() { + return '[ + Query.equal("title", ["Spiderman", "Dr Strange"]), + Query.greaterThan("year", 2000), + Query.orderAsc("title"), + Query.limit(5), + Query.offset(10) + ]'; + } + + public function rolesHelperExample() { + return '[ + Role.any(), + Roles.user(ID.custom("6abdzeeq23dfds")) + ]'; + } + + public function uniqueIDExample() { + return 'ID.unique()'; + } + public function getFilters(): array { return [ @@ -449,7 +478,7 @@ public function getFilters(): array $value[$key] = " /// " . wordwrap($value[$key], 75, "\n /// "); } return implode("\n", $value); - }, ['is_safe' => ['html']]), + }, ['is_safe' => ['html']]) ]; } } diff --git a/src/SDK/Language/JS.php b/src/SDK/Language/JS.php index a6412125a..b0d10170b 100644 --- a/src/SDK/Language/JS.php +++ b/src/SDK/Language/JS.php @@ -192,4 +192,33 @@ public function getParamDefault(array $param) return $output; } + + public function permissionHelperExample() { + return '[ + Permission.read(Role.any()), + Permission.create(Role.user(ID.custom("6abdzeeq23dfds")), + Permission.delete(Role.team(ID.custom("editors"), "owner")), + ]'; + } + + public function queriesHelperExample() { + return '[ + Query.equal("title", ["Spiderman", "Dr Strange"]), + Query.greaterThan("year", 2000), + Query.orderAsc("title"), + Query.limit(5), + Query.offset(10) + ]'; + } + + public function rolesHelperExample() { + return '[ + Role.any(), + Roles.user(ID.custom("6abdzeeq23dfds")) + ]'; + } + + public function uniqueIDExample() { + return 'ID.unique()'; + } } diff --git a/src/SDK/Language/PHP.php b/src/SDK/Language/PHP.php index fed234bc3..e85c9d413 100644 --- a/src/SDK/Language/PHP.php +++ b/src/SDK/Language/PHP.php @@ -395,6 +395,35 @@ protected function getReturn(array $method): string return 'array'; } + public function permissionHelperExample() { + return '[ + Permission::read(Role::any()), + Permission::create(Role::user(ID::custom("6abdzeeq23dfds")), + Permission::delete(Role::team(ID::custom("editors"), "owner")), + ]'; + } + + public function queriesHelperExample() { + return '[ + Query::equal("title", ["Spiderman", "Dr Strange"]), + Query::greaterThan("year", 2000), + Query::orderAsc("title"), + Query::limit(5), + Query::offset(10) + ]'; + } + + public function rolesHelperExample() { + return '[ + Role::any(), + Roles::user(ID::custom("6abdzeeq23dfds")) + ]'; + } + + public function uniqueIDExample() { + return 'ID::unique()'; + } + public function getFilters(): array { return [ new TwigFilter('getReturn', function($value) { diff --git a/src/SDK/SDK.php b/src/SDK/SDK.php index 436d16446..0959e8534 100644 --- a/src/SDK/SDK.php +++ b/src/SDK/SDK.php @@ -82,9 +82,13 @@ public function __construct(Language $language, Spec $spec) foreach ($this->language->getFilters() as $filter) { $this->twig->addFilter($filter); } - + $this->twig->addExtension(new \Twig\Extension\DebugExtension()); + $this->twig->addFilter(new TwigFilter('customLanguageFilter', function($value, $filter) use ($language) { + return call_user_func([$language, $filter], $value); + }, ['is_safe' => ['html']])); + $this->twig->addFilter(new TwigFilter('caseLower', function ($value) { return strtolower((string)$value); })); @@ -556,7 +560,6 @@ public function generate($target) foreach ($this->spec->getServices() as $key => $service) { $methods = $this->spec->getMethods($key); $params['service'] = [ - 'globalParams' => $service['globalParams'] ?? [], 'description' => $service['description'] ?? '', 'name' => $key, 'features' => [ @@ -584,7 +587,6 @@ public function generate($target) $params['service'] = [ 'name' => $key, 'methods' => $methods, - 'globalParams' => $service['globalParams'] ?? [], 'features' => [ 'upload' => $this->hasUploads($methods), 'location' => $this->hasLocation($methods), diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index 28123bf80..ee32bc9cb 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -180,6 +180,7 @@ public function getMethods($service) 'path' => [], 'query' => [], 'body' => [], + 'example' => [], ], 'emptyResponse' => $emptyResponse, 'responseModel' => $responseModel, @@ -192,7 +193,7 @@ public function getMethods($service) } $method['parameters'] = (isset($method['parameters']) && is_array($method['parameters'])) ? $method['parameters'] : []; - + $exampleParams = $method['x-example-params'] ?? []; foreach ($method['parameters'] as $parameter) { $param = [ 'name' => $parameter['name'] ?? null, @@ -202,6 +203,7 @@ public function getMethods($service) 'required' => $parameter['required'] ?? false, 'default' => $parameter['default'] ?? null, 'example' => $parameter['x-example'] ?? null, + 'exampleFilter' => $parameter['x-example-filter'] ?? null, 'isUploadID' => $parameter['x-upload-id'] ?? false, 'array' => [ 'type' => $parameter['items']['type'] ?? '', @@ -239,6 +241,7 @@ public function getMethods($service) $param['default'] = $value['default'] ?? null; $param['example'] = $value['x-example'] ?? null; $param['isUploadID'] = $value['x-upload-id'] ?? false; + $param['exampleFilter'] = $value['x-example-filter'] ?? null; $param['array'] = [ 'type' => $value['items']['type'] ?? '', ]; @@ -250,6 +253,9 @@ public function getMethods($service) $output['parameters']['body'][] = $param; $output['parameters']['all'][] = $param; + if($param['required'] || in_array($param['name'], $exampleParams)) { + $output['parameters']['example'][] = $param; + } } continue 2; @@ -258,6 +264,9 @@ public function getMethods($service) } $output['parameters']['all'][] = $param; + if($param['required'] || in_array($param['name'], $exampleParams)) { + $output['parameters']['example'][] = $param; + } } usort($output['parameters']['all'], function ($a, $b) { diff --git a/templates/dart/docs/example.md.twig b/templates/dart/docs/example.md.twig index f438c7e9c..72ba9c203 100644 --- a/templates/dart/docs/example.md.twig +++ b/templates/dart/docs/example.md.twig @@ -5,7 +5,7 @@ import 'package:{{ language.params.packageName }}/{{ language.params.packageName void main() { // Init SDK Client client = Client(); - {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample }}{% endfor %}{% endif %}); + {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client); {% if method.security|length > 0 %} client @@ -17,14 +17,12 @@ void main() { // Init SDK {% endfor %} ; {% endif %} - Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %} + Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.example %} {% if loop.first %} {% endif %} -{% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }}, -{% endif %} -{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); + {{ parameter.name | caseCamel | overrideIdentifier }}: {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample | replace({'': (parameter.name | caseCamel) }) | raw }}{% endif %}, +{% endfor %}{% if method.parameters.example | length > 0 %} {% endif %}); result .then((response) { diff --git a/templates/deno/docs/example.md.twig b/templates/deno/docs/example.md.twig index 98fb10f19..e1ec8e874 100644 --- a/templates/deno/docs/example.md.twig +++ b/templates/deno/docs/example.md.twig @@ -6,7 +6,7 @@ const fs = require('fs'); // Init SDK let client = new sdk.Client(); -let {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); +let {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client); {% if method.security|length > 0 %} client @@ -19,7 +19,13 @@ 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 }}({% if method.parameters.example | length > 0 %} + +{% endif %} +{% for parameter in method.parameters.example %} + {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}{% if not loop.last %}, {% 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 eb5c4a902..a02ce8877 100644 --- a/templates/dotnet/docs/example.md.twig +++ b/templates/dotnet/docs/example.md.twig @@ -12,6 +12,6 @@ client {% endfor %}; {% endif %} -{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); +{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client); {% if method.type == 'location' %}string{% else %}HttpResponseMessage{% endif %} result = await {{ service.name | caseCamel }}.{{ method.name | caseUcfirst }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %}); diff --git a/templates/flutter/docs/example.md.twig b/templates/flutter/docs/example.md.twig index 44163cffd..ac5f8466d 100644 --- a/templates/flutter/docs/example.md.twig +++ b/templates/flutter/docs/example.md.twig @@ -5,7 +5,7 @@ import 'package:{{ language.params.packageName }}/{{ language.params.packageName void main() { // Init SDK Client client = Client(); - {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample }}{% endfor %}{% endif %}); + {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client); {% if method.security|length > 0 %} client @@ -18,14 +18,12 @@ void main() { // Init SDK {% endif %} {% if method.type == 'location' %} // downloading file - Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %} + Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.example %} {% if loop.first %} {% endif %} -{% if parameter.required %} - {{ parameter.name | caseCamel }}: {{ parameter | paramExample }}, -{% endif %} -{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}).then((bytes) { + {{ parameter.name | caseCamel | overrideIdentifier }}: {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}, +{% endfor %}{% if method.parameters.example | length > 0 %} {% endif %}).then((bytes) { final file = File('path_to_file/filename.ext'); file.writeAsBytesSync(bytes) }).catchError((error) { @@ -35,14 +33,12 @@ void main() { // Init SDK //displaying image preview FutureBuilder( - future: {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %} + future: {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.example %} {% if loop.first %} {% endif %} -{% if parameter.required %} - {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample }}, -{% endif %} -{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %} + {{ parameter.name | caseCamel | overrideIdentifier }}: {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}, +{% endfor %}{% if method.parameters.example | length > 0 %} {% endif %} ), //works for both public file and private file, for private files you need to be logged in builder: (context, snapshot) { return snapshot.hasData && snapshot.data != null @@ -53,14 +49,12 @@ FutureBuilder( }, ); {% else %} - Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %} + Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.example %} {% if loop.first %} {% endif %} -{% if parameter.required %} - {{ parameter.name | caseCamel }}: {{ parameter | paramExample }}, -{% endif %} -{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}); + {{ parameter.name | caseCamel | overrideIdentifier }}: {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}, +{% endfor %}{% if method.parameters.example | length > 0 %} {% endif %}); result .then((response) { diff --git a/templates/kotlin/docs/java/example.md.twig b/templates/kotlin/docs/java/example.md.twig index f91259417..ac1902fbe 100644 --- a/templates/kotlin/docs/java/example.md.twig +++ b/templates/kotlin/docs/java/example.md.twig @@ -13,7 +13,7 @@ public void main() { .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{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); + {{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client); {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}new Continuation() { @NotNull @Override diff --git a/templates/kotlin/docs/kotlin/example.md.twig b/templates/kotlin/docs/kotlin/example.md.twig index 0d7ecb6ce..bd8370e15 100644 --- a/templates/kotlin/docs/kotlin/example.md.twig +++ b/templates/kotlin/docs/kotlin/example.md.twig @@ -13,7 +13,7 @@ suspend fun main() { .set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}} {% endfor %}{% endfor %}{% endif %} - val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% 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 %} {% for parameter in method.parameters.all %} diff --git a/templates/node/docs/example.md.twig b/templates/node/docs/example.md.twig index 33374dd94..ede900dbd 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.security|length > 0 %} client @@ -18,7 +18,13 @@ 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 }}({% if method.parameters.example | length > 0 %} + +{% endif %} +{% for parameter in method.parameters.example %} + {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}{% if not loop.last %}, {% endif %} + +{% endfor %}); promise.then(function (response) { console.log(response); diff --git a/templates/node/index.d.ts.twig b/templates/node/index.d.ts.twig index 39f4acda7..faff27f7b 100644 --- a/templates/node/index.d.ts.twig +++ b/templates/node/index.d.ts.twig @@ -176,27 +176,8 @@ declare module "{{ language.params.npmPackage|caseDash }}" { {% for service in spec.services %} export class {{ service.name | caseUcfirst }} extends Service { - constructor(client: Client{% for parameter in service.globalParams %}, {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter | typeName }}{% if not parameter.required %}|null{% endif %}{% endfor %}); - -{% if service.globalParams | length %} -{% for parameter in service.globalParams %} - /** - * Get {{ parameter.name }}. - * - * @returns {{ '{' }}{{ parameter | typeName }}{{ '}' }} - */ - get{{ parameter.name | caseUcfirst | escapeKeyword }}(): {{ parameter | typeName }}; - - /** - * Set {{ parameter.name }}. - * - * @param {{ '{' }}{{ parameter | typeName }}{{ '}' }} {{ parameter.name | caseCamel | escapeKeyword }} - * @returns {void} - */ - set{{ parameter.name | caseUcfirst | escapeKeyword }}({{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter | typeName }}): void; + constructor(client: Client); -{% endfor %} -{% endif %} {% for method in service.methods %} {% set generics = _self.get_generics_method(spec.definitions[method.responseModel], spec, true, true) %} {% set generics_return = _self.get_generics_method_return(spec.definitions[method.responseModel], spec) %} diff --git a/templates/php/docs/example.md.twig b/templates/php/docs/example.md.twig index 56a2826b1..4dcddee9b 100644 --- a/templates/php/docs/example.md.twig +++ b/templates/php/docs/example.md.twig @@ -18,6 +18,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 %}{{ parameter | paramExample }}{% endif %}{% endfor %}); \ No newline at end of file +$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.example %}{% if not loop.first %}, {% endif %}{% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% 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 aa22527d8..ff0b68113 100644 --- a/templates/python/docs/example.md.twig +++ b/templates/python/docs/example.md.twig @@ -16,6 +16,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 %}{{ parameter | paramExample }}{% endif %}{% endfor %}) diff --git a/templates/ruby/docs/example.md.twig b/templates/ruby/docs/example.md.twig index 341b59022..12c324804 100644 --- a/templates/ruby/docs/example.md.twig +++ b/templates/ruby/docs/example.md.twig @@ -13,7 +13,7 @@ client {% endfor %} {% endfor %} -{{ service.name | caseSnake }} = {{spec.title | caseUcfirst}}::{{ service.name | caseUcfirst }}.new(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{parameter.name | caseSnake}}:{{ parameter | paramExample }}{% endfor %}{% endif %}) +{{ service.name | caseSnake }} = {{spec.title | caseUcfirst}}::{{ 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' %}{{spec.title | caseUcfirst}}::{{ parameter | paramExample }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}) diff --git a/templates/swift/docs/example.md.twig b/templates/swift/docs/example.md.twig index 25a9e95c7..20a8aae37 100644 --- a/templates/swift/docs/example.md.twig +++ b/templates/swift/docs/example.md.twig @@ -10,7 +10,7 @@ func main() async throws { {% endfor %} {% endfor %} {% endif %} - let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}) + let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client) 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) %} diff --git a/templates/web/docs/example.md.twig b/templates/web/docs/example.md.twig index 6e80ad1c3..9bf43a7c0 100644 --- a/templates/web/docs/example.md.twig +++ b/templates/web/docs/example.md.twig @@ -2,7 +2,7 @@ import {{ '{' }} Client, {{service.name | caseUcfirst}} {{ '}' }} from "{{ langu const client = new Client(); -const {{ service.name | caseCamel }} = new {{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %}); +const {{ service.name | caseCamel }} = new {{service.name | caseUcfirst}}(client); {% if method.security|length > 0 %} client @@ -16,7 +16,13 @@ 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 }}({% if method.parameters.example | length > 0 %} + +{% endif %} +{% for parameter in method.parameters.example %} + {% if parameter.exampleFilter %}{{ parameter | customLanguageFilter(parameter.exampleFilter) }}{% else %}{{ parameter | paramExample }}{% endif %}{% if not loop.last %}, {% endif %} + +{% endfor %}); {% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}console.log(result); // Resource URL{% else %}promise.then(function (response) { console.log(response); // Success