Skip to content

Commit 961e19c

Browse files
committed
Merge branch 'master' into feat-improve-deno-file-upload
2 parents 567ee5d + 53481c8 commit 961e19c

File tree

67 files changed

+787
-320
lines changed

Some content is hidden

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

67 files changed

+787
-320
lines changed

specs/swagger2-latest-console.json

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

src/SDK/Language/Dart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getKeywords()
112112
*/
113113
public function getIdentifierOverrides()
114114
{
115-
return ['Function' => 'Func'];
115+
return ['Function' => 'Func', 'default' => 'xdefault', 'required' => 'xrequired'];
116116
}
117117

118118
/**

src/SDK/Language/Python.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public function getParamExample(array $param)
302302
$output .= '{}';
303303
break;
304304
case self::TYPE_FILE:
305-
$output .= "'file.png'";
305+
$output .= "InputFile.from_path('file.png')";
306306
break;
307307
}
308308
}
@@ -321,7 +321,7 @@ public function getParamExample(array $param)
321321
$output .= "'{$example}'";
322322
break;
323323
case self::TYPE_FILE:
324-
$output .= "'file.png'";
324+
$output .= "InputFile.from_path('file.png')";
325325
break;
326326
}
327327
}

src/SDK/Language/Swift.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function getFiles()
155155
[
156156
'scope' => 'default',
157157
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Models/File.swift',
158-
'template' => 'swift/Sources/Models/File.swift.twig',
158+
'template' => 'swift/Sources/Models/InputFile.swift.twig',
159159
'minify' => false,
160160
],
161161
[
@@ -188,6 +188,12 @@ public function getFiles()
188188
'template' => 'swift/Sources/Extensions/HTTPClientRequest+Cookies.swift.twig',
189189
'minify' => false,
190190
],
191+
[
192+
'scope' => 'default',
193+
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/Extensions/String+MimeTypes.swift',
194+
'template' => 'swift/Sources/Extensions/String+MimeTypes.swift.twig',
195+
'minify' => false,
196+
],
191197
[
192198
'scope' => 'default',
193199
'destination' => '/Sources/{{ spec.title | caseUcfirst}}/StreamingDelegate.swift',
@@ -301,7 +307,7 @@ public function getTypeName($type)
301307
case self::TYPE_STRING:
302308
return 'String';
303309
case self::TYPE_FILE:
304-
return 'File';
310+
return 'InputFile';
305311
case self::TYPE_BOOLEAN:
306312
return 'Bool';
307313
case self::TYPE_ARRAY:
@@ -390,7 +396,7 @@ public function getParamExample(array $param)
390396
if(empty($example) && $example !== 0 && $example !== false) {
391397
switch ($type) {
392398
case self::TYPE_FILE:
393-
$output .= 'File(name: "image.jpg", buffer: yourByteBuffer)';
399+
$output .= 'InputFile.fromPath("file.png")';
394400
break;
395401
case self::TYPE_NUMBER:
396402
case self::TYPE_INTEGER:

src/SDK/SDK.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ public function generate($target)
556556
foreach ($this->spec->getServices() as $key => $service) {
557557
$methods = $this->spec->getMethods($key);
558558
$params['service'] = [
559+
'globalParams' => $service['globalParams'] ?? [],
559560
'description' => $service['description'] ?? '',
560561
'name' => $key,
561562
'features' => [
@@ -583,6 +584,7 @@ public function generate($target)
583584
$params['service'] = [
584585
'name' => $key,
585586
'methods' => $methods,
587+
'globalParams' => $service['globalParams'] ?? [],
586588
'features' => [
587589
'upload' => $this->hasUploads($methods),
588590
'location' => $this->hasLocation($methods),

src/Spec/Swagger2.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class Swagger2 extends Spec
88
{
9+
/**
10+
* @var array
11+
*/
12+
private array $serviceParams = [];
913

1014
/**
1115
* @return string
@@ -104,9 +108,11 @@ public function getServices()
104108
if (isset($method['tags'])) {
105109
foreach ($method['tags'] as $tag) {
106110
if (!array_key_exists($tag, $list)) {
111+
$methods = $this->getMethods($tag);
107112
$list[$tag] = [
108113
'name' => $tag,
109-
'methods' => $this->getMethods($tag),
114+
'methods' => $methods,
115+
'globalParams' => $this->serviceParams[$tag] ?? [],
110116
];
111117
}
112118
}
@@ -132,7 +138,7 @@ public function getServices()
132138
public function getMethods($service)
133139
{
134140
$list = [];
135-
141+
$serviceParams= [];
136142
$security = $this->getAttribute('securityDefinitions', []);
137143
$paths = $this->getAttribute('paths', []);
138144

@@ -204,6 +210,7 @@ public function getMethods($service)
204210
'default' => $parameter['default'] ?? null,
205211
'example' => $parameter['x-example'] ?? null,
206212
'isUploadID' => $parameter['x-upload-id'] ?? false,
213+
'isGlobal' => $parameter['x-global'] ?? false,
207214
'array' => [
208215
'type' => $parameter['items']['type'] ?? '',
209216
],
@@ -215,6 +222,10 @@ public function getMethods($service)
215222

216223
$param['default'] = (is_array($param['default'])) ? json_encode($param['default']) : $param['default'];
217224

225+
if(($parameter['x-global'] ?? false)) {
226+
$serviceParams[$param['name']] = $param;
227+
}
228+
218229
switch ($parameter['in']) {
219230
case 'header':
220231
$output['parameters']['header'][] = $param;
@@ -239,6 +250,7 @@ public function getMethods($service)
239250
$param['required'] = (in_array($key, $bodyRequired));
240251
$param['default'] = $value['default'] ?? null;
241252
$param['example'] = $value['x-example'] ?? null;
253+
$param['isGlobal'] = $value['x-global'] ?? false;
242254
$param['isUploadID'] = $value['x-upload-id'] ?? false;
243255
$param['array'] = [
244256
'type' => $value['items']['type'] ?? '',
@@ -270,6 +282,8 @@ public function getMethods($service)
270282
}
271283
}
272284

285+
$this->serviceParams[$service] = $serviceParams;
286+
273287
return $list;
274288
}
275289

templates/android/docs/java/example.md.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class MainActivity extends AppCompatActivity {
2222
{% endfor %}
2323
{% endif %}
2424

25-
{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client);
25+
{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %});
2626

27-
{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}new Continuation<Object>() {
27+
{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => not param.isGlobal) | length == 0 %}new Continuation<Object>() {
2828
@NotNull
2929
@Override
3030
public CoroutineContext getContext() {
@@ -53,7 +53,7 @@ public class MainActivity extends AppCompatActivity {
5353
{% if method.type == "webAuth" %}
5454
this,
5555
{% endif %}
56-
{% for parameter in method.parameters.all %}
56+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
5757
{% if parameter.required %}
5858
{{ parameter | paramExample }}{% if not loop.last %}, {% endif %}
5959

templates/android/docs/kotlin/example.md.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class MainActivity : AppCompatActivity() {
2020
{% endfor %}
2121
{% endif %}
2222

23-
val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)
23+
val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %})
2424

2525
GlobalScope.launch {
26-
{% 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 %}
26+
{% if method.type == 'webAuth' %} {% elseif method.type == 'location' %} val result = {% else %} val response = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => not param.isGlobal) | length == 0 %}){% endif %}
2727

2828
{% if method.type == "webAuth" %}
2929
activity = this@MainActivity,
3030
{% endif %}
31-
{% for parameter in method.parameters.all %}
31+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
3232
{% if parameter.required %}
3333
{{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %}
3434

templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% macro parameter(parameter) %}{{ parameter.name | caseCamel }}: {{ parameter.type | typeName }}{% if not parameter.required %}? = null{% endif %}{% endmacro %}
22
{% macro method_parameters(parameters, consumes) %}
3-
{% if parameters.all|length > 0 %}{% for parameter in parameters.all %}{{ '\n\t\t' }}{{ _self.parameter(parameter) }}{% if not loop.last %}{{ ',' }}{% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, onProgress: ((UploadProgress) -> Unit)? = null{% endif %}{% endif %}
3+
{% if parameters.all|length > 0 %}{% for parameter in parameters.all | filter((param) => not param.isGlobal) %}{{ '\n\t\t' }}{{ _self.parameter(parameter) }}{% if not loop.last %}{{ ',' }}{% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, onProgress: ((UploadProgress) -> Unit)? = null{% endif %}{% endif %}
44
{% endmacro %}
55
{% macro methodNeedsSecurityParameters(method) %}
66
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
@@ -26,7 +26,22 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
2626
{% endif %}
2727
import java.io.File
2828

29-
class {{ service.name | caseUcfirst }}(client: Client) : Service(client) {
29+
class {{ service.name | caseUcfirst }} : Service {
30+
31+
{% if service.globalParams | length %}
32+
{% for parameter in service.globalParams %}
33+
val {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName | overrideIdentifier }}{% if not parameter.required %}?{% endif %}
34+
35+
{% endfor %}
36+
37+
public constructor(client: Client,{% for parameter in service.globalParams %} {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName | overrideIdentifier }}{% if not parameter.required %}? = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}) : super(client) {
38+
{% for parameter in service.globalParams %}
39+
this.{{ parameter.name | caseCamel | escapeKeyword }} = {{ parameter.name | caseCamel | escapeKeyword }}
40+
{% endfor %}
41+
}
42+
{% else %}
43+
public constructor (client: Client) : super(client) { }
44+
{% endif %}
3045

3146
{% for method in service.methods %}
3247
/**
@@ -36,7 +51,7 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) {
3651
{{ method.description|comment1 }}
3752
*
3853
{% endif %}
39-
{% for parameter in method.parameters.all %}
54+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
4055
* @param {{ parameter.name | caseCamel }} {{ parameter.description }}
4156
{% endfor %}
4257
* {% if method.type != "webAuth" %}@return [{{ _self.resultType(sdk.namespace, method) }}]{% endif %}

templates/dart/base/requests/api.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% import 'flutter/base/utils.twig' as utils %}
1+
{% import 'dart/base/utils.twig' as utils %}
22
final Map<String, dynamic> params = {
33
{{ utils.map_parameter(method.parameters.query) }}
44
{{ utils.map_parameter(method.parameters.body) }}

0 commit comments

Comments
 (0)