Skip to content

Commit d8126c7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into CI-run-tests
2 parents 090c572 + dc6720b commit d8126c7

File tree

40 files changed

+223
-224
lines changed

40 files changed

+223
-224
lines changed

.github/workflows/sdk-build-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ jobs:
173173
;;
174174
php)
175175
composer install
176+
find . -name "*.php" ! -path "./vendor/*" -exec php -l {} +
176177
;;
177178
python)
178179
pip install -e .

src/SDK/Language/PHP.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ public function getFiles(): array
172172
'destination' => 'composer.json',
173173
'template' => 'php/composer.json.twig',
174174
],
175+
[
176+
'scope' => 'default',
177+
'destination' => 'phpunit.xml',
178+
'template' => 'php/phpunit.xml.twig',
179+
],
175180
[
176181
'scope' => 'service',
177182
'destination' => 'docs/{{service.name | caseLower}}.md',

src/Spec/Swagger2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected function parseMethod(string $methodName, string $pathName, array $meth
229229
$param['default'] = (is_array($param['default']) || $param['default'] instanceof stdClass) ? json_encode($param['default']) : $param['default'];
230230
if (isset($parameter['enum'])) {
231231
$param['enumValues'] = $parameter['enum'];
232-
$param['enumName'] = $parameter['x-enum-name'];
232+
$param['enumName'] = $parameter['x-enum-name'] ?? $param['name'];
233233
$param['enumKeys'] = $parameter['x-enum-keys'];
234234
}
235235

@@ -268,7 +268,7 @@ protected function parseMethod(string $methodName, string $pathName, array $meth
268268

269269
if (isset($value['enum'])) {
270270
$temp['enumValues'] = $value['enum'];
271-
$temp['enumName'] = $value['x-enum-name'];
271+
$temp['enumName'] = $value['x-enum-name'] ?? $temp['name'];
272272
$temp['enumKeys'] = $value['x-enum-keys'];
273273
}
274274

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

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import {{ sdk.namespace | caseDot }}.models.InputFile;
66
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }};
77
{% set added = [] %}
88
{% for parameter in method.parameters.all %}
9-
{% if method == parameter.required %}
109
{% if parameter.enumValues is not empty %}
11-
{% if parameter.enumName is not empty %}
12-
{% set name = parameter.enumName %}
13-
{% else %}
14-
{% set name = parameter.name %}
15-
{% endif %}
16-
{% if name not in added %}
17-
import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }};
18-
{% set added = added|merge([name]) %}
19-
{% endif %}
10+
{% if parameter.enumName not in added %}
11+
import {{ sdk.namespace | caseDot }}.enums.{{ parameter.enumName | caseUcfirst }};
12+
{% set added = added|merge([parameter.enumName]) %}
2013
{% endif %}
2114
{% endif %}
2215
{% endfor %}
@@ -47,17 +40,10 @@ Client client = new Client(context)
4740
}));{% endif %}
4841

4942
{% for parameter in method.parameters.all %}
50-
{%~ if parameter.enumValues is not empty -%}
51-
{%~ if parameter.enumName is not empty -%}
52-
{%~ set name = parameter.enumName -%}
53-
{%~ else -%}
54-
{%~ set name = parameter.name -%}
55-
{%~ endif %}
56-
{{ name }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}, // {{ parameter.name }} {% if not parameter.required %}(optional){% endif %}
57-
{%~ else %}
58-
{{ parameter | paramExample }}, // {{ parameter.name }} {% if not parameter.required %}(optional){% endif %}
59-
{%~ endif %}
60-
{%~ if loop.last %}
43+
{% if parameter.enumValues is not empty %}{{ parameter.enumName | caseUcfirst }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}, // {{ parameter.name }} {% if not parameter.required %}(optional){% endif %}
44+
{% else %}{{ parameter | paramExample }}, // {{ parameter.name }} {% if not parameter.required %}(optional){% endif %}
45+
{% endif %}
46+
{%~ if loop.last %}
6147

6248
new CoroutineCallback<>((result, error) -> {
6349
if (error != null) {

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,10 @@ import {{ sdk.namespace | caseDot }}.models.InputFile
66
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
77
{% set added = [] %}
88
{% for parameter in method.parameters.all %}
9-
{% if method == parameter.required %}
109
{% if parameter.enumValues is not empty %}
11-
{% if parameter.enumName is not empty %}
12-
{% set name = parameter.enumName %}
13-
{% else %}
14-
{% set name = parameter.name %}
15-
{% endif %}
16-
{% if name not in added %}
17-
import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }}
18-
{% set added = added|merge([name]) %}
19-
{% endif %}
10+
{% if parameter.enumName not in added %}
11+
import {{ sdk.namespace | caseDot }}.enums.{{ parameter.enumName | caseUcfirst }}
12+
{% set added = added|merge([parameter.enumName]) %}
2013
{% endif %}
2114
{% endif %}
2215
{% endfor %}
@@ -42,13 +35,8 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)
4235
val result = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %}
4336

4437
{%~ for parameter in method.parameters.all %}
45-
{%~ if parameter.enumValues is not empty -%}
46-
{%~ if parameter.enumName is not empty -%}
47-
{%~ set name = parameter.enumName -%}
48-
{%~ else -%}
49-
{%~ set name = parameter.name -%}
50-
{%~ endif %}
51-
{{ parameter.name }} = {{ name }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }},{% if not parameter.required %} // (optional){% endif %}
38+
{%~ if parameter.enumValues is not empty %}
39+
{{ parameter.name }} = {{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }},{% if not parameter.required %} // (optional){% endif %}
5240
{%~ else %}
5341
{{ parameter.name }} = {{ parameter | paramExample }}, {% if not parameter.required %}// (optional){% endif %}
5442
{%~ endif %}

templates/apple/Sources/Client.swift.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import NIOSSL
55
import Foundation
66
import AsyncHTTPClient
77
@_exported import {{spec.title | caseUcfirst}}Models
8+
@_exported import JSONCodable
89

910
let DASHDASH = "--"
1011
let CRLF = "\r\n"

templates/cli/lib/type-generation/languages/csharp.js.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class CSharp extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "string";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -60,7 +60,7 @@ namespace Appwrite.Models
6060
<% for (const attribute of collection.attributes) { -%>
6161
<% if (attribute.format === 'enum') { -%>
6262

63-
public enum <%- toPascalCase(attribute.key) %> {
63+
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6464
<% for (const [index, element] of Object.entries(attribute.elements) ) { -%>
6565
[JsonPropertyName("<%- element %>")]
6666
<%- toPascalCase(element) %><% if (index < attribute.elements.length - 1) { %>,<% } %>
@@ -72,13 +72,13 @@ public class <%= toPascalCase(collection.name) %>
7272
{
7373
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
7474
[JsonPropertyName("<%- attribute.key %>")]
75-
public <%- getType(attribute, collections) %> <%= toPascalCase(attribute.key) %> { get; private set; }
75+
public <%- getType(attribute, collections, collection.name) %> <%= toPascalCase(attribute.key) %> { get; private set; }
7676

7777
<% } -%>
7878

7979
public <%= toPascalCase(collection.name) %>(
8080
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
81-
<%- getType(attribute, collections) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
81+
<%- getType(attribute, collections, collection.name) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
8282
<% } -%>
8383
)
8484
{
@@ -93,9 +93,9 @@ public class <%= toPascalCase(collection.name) %>
9393
// ENUM
9494
if (attribute.format === 'enum') {
9595
if (attribute.array) {
96-
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
96+
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
9797
} else {
98-
-%>Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
98+
-%>Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
9999
}
100100
// RELATIONSHIP
101101
} else if (attribute.type === 'relationship') {
@@ -122,7 +122,7 @@ public class <%= toPascalCase(collection.name) %>
122122
} else if (attribute.type === 'double') {
123123
-%><%- !attribute.required ? 'map["' + attribute.key + '"] == null ? null : ' : '' %>Convert.ToDouble(map["<%- attribute.key %>"])<%
124124
} else if (attribute.type === 'boolean') {
125-
-%>(<%- getType(attribute, collections) %>)map["<%- attribute.key %>"]<%
125+
-%>(<%- getType(attribute, collections, collection.name) %>)map["<%- attribute.key %>"]<%
126126
} else if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
127127
-%>map["<%- attribute.key %>"]<%- !attribute.required ? '?' : '' %>.ToString()<%- attribute.required ? '!' : ''%><%
128128
} else {

templates/cli/lib/type-generation/languages/dart.js.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Dart extends LanguageMeta {
4040
return 'appwrite';
4141
}
4242

43-
getType(attribute, collections) {
43+
getType(attribute, collections, collectionName) {
4444
let type = "";
4545
switch (attribute.type) {
4646
case AttributeType.STRING:
4747
case AttributeType.EMAIL:
4848
case AttributeType.DATETIME:
4949
type = "String";
5050
if (attribute.format === AttributeType.ENUM) {
51-
type = LanguageMeta.toPascalCase(attribute.key);
51+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
5252
}
5353
break;
5454
case AttributeType.INTEGER:
@@ -103,7 +103,7 @@ import '<%- toSnakeCase(related.name) %>.dart';
103103

104104
<% for (const attribute of __attrs) { -%>
105105
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
106-
enum <%- toPascalCase(attribute.key) %> {
106+
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
107107
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
108108
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { -%>,<% } %>
109109
<% } -%>
@@ -113,7 +113,7 @@ enum <%- toPascalCase(attribute.key) %> {
113113
<% } -%>
114114
class <%= toPascalCase(collection.name) %> {
115115
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
116-
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
116+
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
117117
<% } -%>
118118

119119
<%= toPascalCase(collection.name) %>({
@@ -128,10 +128,10 @@ class <%= toPascalCase(collection.name) %> {
128128
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
129129
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
130130
<% if (attribute.array) { -%>
131-
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
131+
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
132132
<% if (!attribute.required) { -%>
133-
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
134-
<%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
133+
map['<%= attribute.key %>'] != null ? <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
134+
<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
135135
<% } -%>
136136
<% } else { -%>
137137
<% if (attribute.array) { -%>

templates/cli/lib/type-generation/languages/java.js.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class Java extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "String";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -61,7 +61,7 @@ public class <%- toPascalCase(collection.name) %> {
6161
<% for (const attribute of collection.attributes) { -%>
6262
<% if (attribute.format === 'enum') { -%>
6363

64-
public enum <%- toPascalCase(attribute.key) %> {
64+
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6565
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
6666
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
6767
<% } -%>
@@ -70,15 +70,15 @@ public class <%- toPascalCase(collection.name) %> {
7070
<% } -%>
7171
<% } -%>
7272
<% for (const attribute of collection.attributes) { -%>
73-
private <%- getType(attribute, collections) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
73+
private <%- getType(attribute, collections, collection.name) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
7474
<% } -%>
7575

7676
public <%- toPascalCase(collection.name) %>() {
7777
}
7878

7979
public <%- toPascalCase(collection.name) %>(
8080
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
81-
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
81+
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
8282
<% } -%>
8383
) {
8484
<% for (const attribute of collection.attributes) { -%>
@@ -87,11 +87,11 @@ public class <%- toPascalCase(collection.name) %> {
8787
}
8888

8989
<% for (const attribute of collection.attributes) { -%>
90-
public <%- getType(attribute, collections) %> get<%- toPascalCase(attribute.key) %>() {
90+
public <%- getType(attribute, collections, collection.name) %> get<%- toPascalCase(attribute.key) %>() {
9191
return <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9292
}
9393

94-
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
94+
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
9595
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9696
}
9797

templates/cli/lib/type-generation/languages/kotlin.js.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class Kotlin extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "String";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -61,7 +61,7 @@ import <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollect
6161

6262
<% for (const attribute of collection.attributes) { -%>
6363
<% if (attribute.format === 'enum') { -%>
64-
enum class <%- toPascalCase(attribute.key) %> {
64+
enum class <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6565
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
6666
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
6767
<% } -%>
@@ -71,7 +71,7 @@ enum class <%- toPascalCase(attribute.key) %> {
7171
<% } -%>
7272
data class <%- toPascalCase(collection.name) %>(
7373
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
74-
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
74+
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections, collection.name) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7575
<% } -%>
7676
)
7777
`;

0 commit comments

Comments
 (0)