Skip to content

Commit ea69431

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat-nested-array-types
# Conflicts: # templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig
2 parents 60f742e + 1ac51c7 commit ea69431

File tree

11 files changed

+137
-126
lines changed

11 files changed

+137
-126
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% import 'kotlin/base/utils.twig' as utils%}
2+
return client.call(
3+
"{{ method.method | caseUpper }}",
4+
path,
5+
headers,
6+
params,
7+
responseType = {{ utils.resultType(sdk.namespace, method) }}::class.java,
8+
{% if method.responseModel %}
9+
converter,
10+
{% endif %}
11+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{% import 'kotlin/base/utils.twig' as utils %}
2+
val idParamName: String? = {% if method.parameters.all | filter(p => p.isUploadID) | length > 0 %}{% for parameter in method.parameters.all | filter(parameter => parameter.isUploadID) %}"{{ parameter.name }}"{% endfor %}{% else %}null{% endif %}
3+
4+
{% for parameter in method.parameters.all %}
5+
{% if parameter.type == 'file' %}
6+
val paramName = "{{ parameter.name }}"
7+
{% endif %}
8+
{% endfor %}
9+
return client.chunkedUpload(
10+
path,
11+
headers,
12+
params,
13+
responseType = {{ utils.resultType(sdk.namespace, method) }}::class.java,
14+
{% if method.responseModel %}
15+
converter,
16+
{% endif %}
17+
paramName,
18+
idParamName,
19+
onProgress,
20+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% import 'kotlin/base/utils.twig' as utils%}
2+
return client.call(
3+
"{{ method.method | caseUpper }}",
4+
path,
5+
params = params,
6+
responseType = {{ utils.resultType(sdk.namespace, method) }}::class.java
7+
)

templates/kotlin/base/utils.twig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% macro parameter(parameter) %}{{ parameter.name | caseCamel }}: {{ parameter | typeName }}{% if not parameter.required %}? = null{% endif %}{% endmacro %}
2+
{% macro method_parameters(parameters, consumes) %}
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 %}
4+
{% endmacro %}
5+
{% macro methodNeedsSecurityParameters(method) %}
6+
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
7+
{% endmacro %}
8+
{% macro resultType(namespace, method) %}
9+
{% if method.type == "webAuth" %}Bool{% elseif method.type == "location" %}ByteArray{% elseif not method.responseModel or method.responseModel == 'any' %}Any{% else %}{{ namespace | caseDot}}.models.{{method.responseModel | caseUcfirst}}{% endif %}
10+
{% endmacro %}

templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
{% macro parameter(parameter) %}{{ parameter.name | caseCamel }}: {{ parameter | typeName }}{% if not parameter.required %}? = null{% endif %}{% endmacro %}
2-
{% macro method_parameters(parameters, consumes) %}
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 %}
4-
{% endmacro %}
5-
{% macro methodNeedsSecurityParameters(method) %}
6-
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
7-
{% endmacro %}
8-
{% macro resultType(namespace, method) %}
9-
{% if method.type == "webAuth" %}Bool{% elseif method.type == "location" %}ByteArray{% elseif not method.responseModel or method.responseModel == 'any' %}Any{% else %}{{ namespace | caseDot}}.models.{{method.responseModel | caseUcfirst}}{% endif %}
10-
{% endmacro %}
1+
{% import 'kotlin/base/utils.twig' as utils %}
112
package {{ sdk.namespace | caseDot }}.services
123
import {{ sdk.namespace | caseDot }}.Client
134
import {{ sdk.namespace | caseDot }}.models.*
@@ -52,20 +43,20 @@ class {{ service.name | caseUcfirst }} : Service {
5243
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
5344
* @param {{ parameter.name | caseCamel }} {{ parameter.description }}
5445
{% endfor %}
55-
* {% if method.type != "webAuth" %}@return [{{ _self.resultType(sdk.namespace, method) }}]{% endif %}
46+
* {% if method.type != "webAuth" %}@return [{{ utils.resultType(sdk.namespace, method) }}]{% endif %}
5647

5748
*/
5849
@JvmOverloads
5950
@Throws({{ spec.title | caseUcfirst }}Exception::class)
60-
suspend fun {{ method.name | caseCamel }}({% if method.type == "webAuth" %}{{ '\n\t\t' }}activity: ComponentActivity{% if method.parameters.all | length > 0 %}, {% endif %}{% endif %}{{ _self.method_parameters(method.parameters, method.consumes) }}{% if method.parameters.all|length > 0 %}{{ '\n\t' }}{% endif %}){% if method.type != "webAuth" %}: {{ _self.resultType(sdk.namespace, method) }}{% endif %} {
51+
suspend fun {{ method.name | caseCamel }}({% if method.type == "webAuth" %}{{ '\n\t\t' }}activity: ComponentActivity{% if method.parameters.all | length > 0 %}, {% endif %}{% endif %}{{ utils.method_parameters(method.parameters, method.consumes) }}{% if method.parameters.all|length > 0 %}{{ '\n\t' }}{% endif %}){% if method.type != "webAuth" %}: {{ utils.resultType(sdk.namespace, method) }}{% endif %} {
6152
val path = "{{ method.path }}"{% for parameter in method.parameters.path %}.replace("{{ '{' ~ parameter.name | caseCamel ~ '}' }}", {{ parameter.name | caseCamel }}){% endfor %}
6253

6354
val params = mutableMapOf<String, Any?>(
6455
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
65-
"{{ parameter.name }}" to {{ parameter.name | caseCamel }}{% if not loop.last or _self.methodNeedsSecurityParameters(method) %},{% endif %}
56+
"{{ parameter.name }}" to {{ parameter.name | caseCamel }}{% if not loop.last or utils.methodNeedsSecurityParameters(method) %},{% endif %}
6657

6758
{% endfor %}
68-
{% if _self.methodNeedsSecurityParameters(method) %}
59+
{% if utils.methodNeedsSecurityParameters(method) %}
6960
{% for node in method.security %}
7061
{% for key,header in node|keys %}
7162
"{{header|caseLower}}" to client.config["{{header|caseLower}}"]{% if not loop.last %},{% endif %}
@@ -116,59 +107,27 @@ class {{ service.name | caseUcfirst }} : Service {
116107
)
117108
}
118109
{% elseif method.type == 'location' %}
119-
return client.call(
120-
"{{ method.method | caseUpper }}",
121-
path,
122-
params = params,
123-
responseType = {{ _self.resultType(sdk.namespace, method) }}::class.java
124-
)
110+
{{ include('kotlin/base/requests/location.twig') }}
125111
{% else %}
126112
val headers = mutableMapOf(
127113
{{ method.headers|map((header, key) => " \"#{key}\" to \"#{header}\"")|join(',\n')|raw }}
128114
)
129115
{% if method.responseModel %}
130-
val converter: (Map<String, Any>) -> {{ _self.resultType(sdk.namespace, method) }} = {
116+
val converter: (Map<String, Any>) -> {{ utils.resultType(sdk.namespace, method) }} = {
131117
{% if method.responseModel == 'any' %}
132118
it
133119
{% else %}
134-
{{ _self.resultType(sdk.namespace, method) }}.from(map = it)
120+
{{ utils.resultType(sdk.namespace, method) }}.from(map = it)
135121
{% endif %}
136122
}
137123
{% endif %}
138124
{% if 'multipart/form-data' in method.consumes %}
139-
val idParamName: String? = {% if method.parameters.all | filter(p => p.isUploadID) | length > 0 %}{% for parameter in method.parameters.all | filter(parameter => parameter.isUploadID) %}"{{ parameter.name }}"{% endfor %}{% else %}null{% endif %}
140-
141-
{% for parameter in method.parameters.all %}
142-
{% if parameter.type == 'file' %}
143-
val paramName = "{{ parameter.name }}"
144-
{% endif %}
145-
{% endfor %}
146-
return client.chunkedUpload(
147-
path,
148-
headers,
149-
params,
150-
responseType = {{ _self.resultType(sdk.namespace, method) }}::class.java,
151-
{% if method.responseModel %}
152-
converter,
153-
{% endif %}
154-
paramName,
155-
idParamName,
156-
onProgress,
157-
)
125+
{{include('kotlin/base/requests/file.twig')}}
158126
{% else %}
159-
return client.call(
160-
"{{ method.method | caseUpper }}",
161-
path,
162-
headers,
163-
params,
164-
responseType = {{ _self.resultType(sdk.namespace, method) }}::class.java,
165-
{% if method.responseModel %}
166-
converter,
167-
{% endif %}
168-
)
127+
{{include('kotlin/base/requests/api.twig')}}
169128
{% endif %}
170129
{% endif %}
171130
}
172131

173132
{% endfor %}
174-
}
133+
}

templates/swift/Sources/Services/Service.swift.twig

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{% macro methodNeedsSecurityParameters(method) %}
2-
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
3-
{% endmacro %}
41
{% macro resultType(spec, method) %}
52
{% if method.type == "webAuth" %}Bool{% elseif method.type == "location" %}ByteBuffer{% elseif not method.responseModel or method.responseModel == 'any' %}Any{% else %}{{spec.title | caseUcfirst}}Models.{{method.responseModel | caseUcfirst}}{% endif %}
63
{% endmacro %}
@@ -51,53 +48,11 @@ open class {{ service.name | caseUcfirst }}: Service {
5148
onProgress: ((UploadProgress) -> Void)? = nil
5249
{% endif %}
5350
) async throws -> {{ _self.resultType(spec, method) }} {
54-
{% if method.parameters.path %} var{% else %} let{% endif %} path: String = "{{ method.path }}"
55-
{% for parameter in method.parameters.path %}
56-
path = path.replacingOccurrences(
57-
of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}",
58-
with: {% if method.parameters.path %}{% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% else %}""{% endif %}
59-
60-
)
61-
{% endfor %}
62-
{% if method.parameters.query or method.parameters.body or method.parameters.formData or _self.methodNeedsSecurityParameters(method) %}
63-
{% if 'multipart/form-data' in method.consumes %}var{% else %}let{% endif %} params: [String: Any?] = [
64-
{% else %}
65-
let params: [String: Any?] = [:]
66-
{% endif %}
67-
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
68-
"{{ parameter.name }}": {% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or _self.methodNeedsSecurityParameters(method) %},{% endif %}
69-
70-
{% endfor %}
71-
{% if _self.methodNeedsSecurityParameters(method) %}
72-
{% for node in method.security %}
73-
{% for key,header in node|keys %}
74-
"{{header|caseLower}}": client.config["{{header|caseLower}}"]{% if not loop.last %},{% endif %}
75-
76-
{% endfor %}
77-
{% endfor %}
78-
{% endif %}
79-
{% if method.parameters.query or method.parameters.body or method.parameters.formData or _self.methodNeedsSecurityParameters(method) %}
80-
]
81-
{% endif %}
51+
{{include('swift/base/params.twig')}}
8252
{% if method.type == 'webAuth' %}
83-
let query = "?\(client.parametersToQueryString(params: params))"
84-
let url = URL(string: client.endPoint + path + query)!
85-
let callbackScheme = "appwrite-callback-\(client.config["project"] ?? "")"
86-
let group = DispatchGroup()
87-
88-
group.enter()
89-
WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in
90-
group.leave()
91-
}
92-
group.wait()
93-
94-
return true
53+
{{include('swift/base/requests/OAuth.twig')}}
9554
{% elseif method.type == 'location' %}
96-
return try await client.call(
97-
method: "{{ method.method | caseUpper }}",
98-
path: path,
99-
params: params
100-
)
55+
{{include('swift/base/requests/location.twig')}}
10156
{% else %}
10257
{% if 'multipart/form-data' in method.consumes %}var{% else %}let{% endif %} headers: [String: String] = [
10358
{{ method.headers|map((header, key) => " \"#{key}\": \"#{header}\"")|join(',\n')|raw }}
@@ -112,33 +67,9 @@ open class {{ service.name | caseUcfirst }}: Service {
11267
}
11368
{% endif %}
11469
{% if 'multipart/form-data' in method.consumes %}
115-
let idParamName: String? = {% if method.parameters.all | filter(p => p.isUploadID) | length > 0 %}{% for parameter in method.parameters.all | filter(parameter => parameter.isUploadID) %}"{{ parameter.name }}"{% endfor %}{% else %}nil{% endif %}
116-
117-
{% for parameter in method.parameters.all %}
118-
{% if parameter.type == 'file' %}
119-
let paramName = "{{ parameter.name }}"
120-
{% endif %}
121-
{% endfor %}
122-
return try await client.chunkedUpload(
123-
path: path,
124-
headers: &headers,
125-
params: &params,
126-
paramName: paramName,
127-
idParamName: idParamName,
128-
{% if method.responseModel %}
129-
converter: converter,
130-
{% endif %}
131-
onProgress: onProgress
132-
)
70+
{{include('swift/base/requests/file.twig')}}
13371
{% else %}
134-
return try await client.call(
135-
method: "{{ method.method | caseUpper }}",
136-
path: path,
137-
headers: headers,
138-
params: params{% if method.responseModel %},
139-
converter: converter
140-
{% endif %}
141-
)
72+
{{include('swift/base/requests/api.twig')}}
14273
{% endif %}
14374
{% endif %}
14475
}

templates/swift/base/params.twig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% macro methodNeedsSecurityParameters(method) %}
2+
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
3+
{% endmacro %}
4+
{% if method.parameters.path %} var{% else %} let{% endif %} path: String = "{{ method.path }}"
5+
{% for parameter in method.parameters.path %}
6+
path = path.replacingOccurrences(
7+
of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}",
8+
with: {% if method.parameters.path %}{% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% else %}""{% endif %}
9+
)
10+
{% endfor %}
11+
{% if method.parameters.query or method.parameters.body or method.parameters.formData or _self.methodNeedsSecurityParameters(method) %}
12+
{% if 'multipart/form-data' in method.consumes %}var{% else %}let{% endif %} params: [String: Any?] = [
13+
{% else %}
14+
let params: [String: Any?] = [:]
15+
{% endif %}
16+
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
17+
"{{ parameter.name }}": {% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or _self.methodNeedsSecurityParameters(method) %},{% endif %}
18+
19+
{% endfor %}
20+
{% if _self.methodNeedsSecurityParameters(method) %}
21+
{% for node in method.security %}
22+
{% for key,header in node|keys %}
23+
"{{header|caseLower}}": client.config["{{header|caseLower}}"]{% if not loop.last %},{% endif %}
24+
25+
{% endfor %}
26+
{% endfor %}
27+
{% endif %}
28+
{% if method.parameters.query or method.parameters.body or method.parameters.formData or _self.methodNeedsSecurityParameters(method) %}
29+
]
30+
{% endif %}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let query = "?\(client.parametersToQueryString(params: params))"
2+
let url = URL(string: client.endPoint + path + query)!
3+
let callbackScheme = "appwrite-callback-\(client.config["project"] ?? "")"
4+
let group = DispatchGroup()
5+
6+
group.enter()
7+
WebAuthComponent.authenticate(url: url, callbackScheme: callbackScheme) { result in
8+
group.leave()
9+
}
10+
group.wait()
11+
12+
return true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
return try await client.call(
2+
method: "{{ method.method | caseUpper }}",
3+
path: path,
4+
headers: headers,
5+
params: params{% if method.responseModel %},
6+
converter: converter
7+
{% endif %}
8+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let idParamName: String? = {% if method.parameters.all | filter(p => p.isUploadID) | length > 0 %}{% for parameter in method.parameters.all | filter(parameter => parameter.isUploadID) %}"{{ parameter.name }}"{% endfor %}{% else %}nil{% endif %}
2+
3+
{% for parameter in method.parameters.all %}
4+
{% if parameter.type == 'file' %}
5+
let paramName = "{{ parameter.name }}"
6+
{% endif %}
7+
{% endfor %}
8+
return try await client.chunkedUpload(
9+
path: path,
10+
headers: &headers,
11+
params: &params,
12+
paramName: paramName,
13+
idParamName: idParamName,
14+
{% if method.responseModel %}
15+
converter: converter,
16+
{% endif %}
17+
onProgress: onProgress
18+
)

0 commit comments

Comments
 (0)