Skip to content

Commit 1856801

Browse files
Merge pull request #476 from appwrite/feat-kt-service-level-params
Android + Kotlin service level parameters
2 parents 6a229de + f2d7e6c commit 1856801

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

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/kotlin/src/main/kotlin/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 %}
@@ -24,7 +24,22 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
2424
{% endif %}
2525
import java.io.File
2626

27-
class {{ service.name | caseUcfirst }}(client: Client) : Service(client) {
27+
class {{ service.name | caseUcfirst }} : Service {
28+
29+
{% if service.globalParams | length %}
30+
{% for parameter in service.globalParams %}
31+
val {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName | overrideIdentifier }}{% if not parameter.required %}?{% endif %}
32+
33+
{% endfor %}
34+
35+
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) {
36+
{% for parameter in service.globalParams %}
37+
this.{{ parameter.name | caseCamel | escapeKeyword }} = {{ parameter.name | caseCamel | escapeKeyword }}
38+
{% endfor %}
39+
}
40+
{% else %}
41+
public constructor (client: Client) : super(client) { }
42+
{% endif %}
2843

2944
{% for method in service.methods %}
3045
/**
@@ -34,7 +49,7 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) {
3449
{{ method.description|comment1 }}
3550
*
3651
{% endif %}
37-
{% for parameter in method.parameters.all %}
52+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
3853
* @param {{ parameter.name | caseCamel }} {{ parameter.description }}
3954
{% endfor %}
4055
* {% if method.type != "webAuth" %}@return [{{ _self.resultType(sdk.namespace, method) }}]{% endif %}

tests/languages/android/ServiceTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ServiceTest {
5959
.setProject("console")
6060
.addHeader("Origin", "http://localhost")
6161
.setSelfSigned(true)
62-
val foo = Foo(client)
62+
val foo = Foo(client, "string")
6363
val bar = Bar(client)
6464
val general = General(client)
6565
val realtime = Realtime(client)
@@ -72,15 +72,15 @@ class ServiceTest {
7272
runBlocking {
7373
var mock: Mock
7474
// Foo Tests
75-
mock = foo.get("string", 123, listOf("string in array"))
75+
mock = foo.get(123, listOf("string in array"))
7676
writeToFile(mock.result)
77-
mock = foo.post("string", 123, listOf("string in array"))
77+
mock = foo.post(123, listOf("string in array"))
7878
writeToFile(mock.result)
79-
mock = foo.put("string", 123, listOf("string in array"))
79+
mock = foo.put(123, listOf("string in array"))
8080
writeToFile(mock.result)
81-
mock = foo.patch("string", 123, listOf("string in array"))
81+
mock = foo.patch(123, listOf("string in array"))
8282
writeToFile(mock.result)
83-
mock = foo.delete("string", 123, listOf("string in array"))
83+
mock = foo.delete(123, listOf("string in array"))
8484
writeToFile(mock.result)
8585

8686
// Bar Tests

tests/languages/kotlin/ServiceTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ class ServiceTest {
3434
val client = Client()
3535
.addHeader("Origin", "http://localhost")
3636
.setSelfSigned(true)
37-
val foo = Foo(client)
37+
val foo = Foo(client, "string")
3838
val bar = Bar(client)
3939
val general = General(client)
4040

4141
runBlocking {
4242
var mock: Mock
4343
// Foo Tests
44-
mock = foo.get("string", 123, listOf("string in array"))
44+
mock = foo.get(123, listOf("string in array"))
4545
writeToFile(mock.result)
46-
mock = foo.post("string", 123, listOf("string in array"))
46+
mock = foo.post(123, listOf("string in array"))
4747
writeToFile(mock.result)
48-
mock = foo.put("string", 123, listOf("string in array"))
48+
mock = foo.put(123, listOf("string in array"))
4949
writeToFile(mock.result)
50-
mock = foo.patch("string", 123, listOf("string in array"))
50+
mock = foo.patch(123, listOf("string in array"))
5151
writeToFile(mock.result)
52-
mock = foo.delete("string", 123, listOf("string in array"))
52+
mock = foo.delete(123, listOf("string in array"))
5353
writeToFile(mock.result)
5454

5555
// Bar Tests

0 commit comments

Comments
 (0)