Skip to content

Commit c729a6c

Browse files
committed
add fix to rest of the langs as well
1 parent 943c507 commit c729a6c

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

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

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

43-
getType(attribute) {
43+
getType(attribute, collections) {
4444
let type = "";
4545
switch (attribute.type) {
4646
case AttributeType.STRING:
@@ -61,7 +61,8 @@ class Dart extends LanguageMeta {
6161
type = "bool";
6262
break;
6363
case AttributeType.RELATIONSHIP:
64-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
64+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
65+
type = LanguageMeta.toPascalCase(relatedCollection.name);
6566
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
6667
type = `List<${type}>`;
6768
}
@@ -104,7 +105,7 @@ enum <%- toPascalCase(attribute.key) %> {
104105
<% } -%>
105106
class <%= toPascalCase(collection.name) %> {
106107
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
107-
<%- getType(attribute) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
108+
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
108109
<% } -%>
109110

110111
<%= toPascalCase(collection.name) %>({

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

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

88
class JavaScript extends LanguageMeta {
9-
getType(attribute) {
9+
getType(attribute, collections) {
1010
let type = ""
1111
switch (attribute.type) {
1212
case AttributeType.STRING:
@@ -29,7 +29,8 @@ class JavaScript extends LanguageMeta {
2929
type = "boolean";
3030
break;
3131
case AttributeType.RELATIONSHIP:
32-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
32+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
33+
type = LanguageMeta.toPascalCase(relatedCollection.name);
3334
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
3435
type = `${type}[]`;
3536
}
@@ -86,7 +87,7 @@ class JavaScript extends LanguageMeta {
8687
<% for (const collection of collections) { %>/**
8788
* @typedef {Document & {
8889
<% for (const attribute of collection.attributes) { -%>
89-
* <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>;
90+
* <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>;
9091
<% } -%>
9192
* }} <%- toPascalCase(collection.name) %>
9293
*/

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

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

55
class Kotlin extends LanguageMeta {
6-
getType(attribute) {
6+
getType(attribute, collections) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
@@ -24,7 +24,8 @@ class Kotlin extends LanguageMeta {
2424
type = "Boolean";
2525
break;
2626
case AttributeType.RELATIONSHIP:
27-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
27+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
28+
type = LanguageMeta.toPascalCase(relatedCollection.name);
2829
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
2930
type = `List<${type}>`;
3031
}
@@ -71,7 +72,7 @@ enum class <%- toPascalCase(attribute.key) %> {
7172
<% } -%>
7273
data class <%- toPascalCase(collection.name) %>(
7374
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
74-
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
75+
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7576
<% } -%>
7677
)`;
7778
}

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

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

55
class PHP extends LanguageMeta {
6-
getType(attribute) {
6+
getType(attribute, collections) {
77
if (attribute.array) {
88
return "array";
99
}
@@ -27,7 +27,8 @@ class PHP extends LanguageMeta {
2727
type = "bool";
2828
break;
2929
case AttributeType.RELATIONSHIP:
30-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
30+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
31+
type = LanguageMeta.toPascalCase(relatedCollection.name);
3132
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
3233
type = "array";
3334
}
@@ -70,15 +71,15 @@ enum <%- toPascalCase(attribute.key) %>: string {
7071
<% } -%>
7172
class <%- toPascalCase(collection.name) %> {
7273
<% for (const attribute of collection.attributes ){ -%>
73-
private <%- getType(attribute) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
74+
private <%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
7475
<% } -%>
7576
7677
public function __construct(
7778
<% for (const attribute of collection.attributes ){ -%>
7879
<% if (attribute.required) { -%>
79-
<%- getType(attribute).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
80+
<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8081
<% } else { -%>
81-
?<%- getType(attribute).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
82+
?<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8283
<% } -%>
8384
<% } -%>
8485
) {
@@ -88,11 +89,11 @@ class <%- toPascalCase(collection.name) %> {
8889
}
8990
9091
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
91-
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute) %> {
92+
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections) %> {
9293
return $this-><%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9394
}
9495
95-
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
96+
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
9697
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9798
}
9899
<% if (index < collection.attributes.length - 1) { %>

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

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

55
class Swift extends LanguageMeta {
6-
getType(attribute) {
6+
getType(attribute, collections) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
@@ -24,7 +24,8 @@ class Swift extends LanguageMeta {
2424
type = "Bool";
2525
break;
2626
case AttributeType.RELATIONSHIP:
27-
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
27+
const relatedCollection = collections.find(c => c.$id === attribute.relatedCollection);
28+
type = LanguageMeta.toPascalCase(relatedCollection.name);
2829
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
2930
type = `[${type}]`;
3031
}
@@ -63,7 +64,7 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
6364
<% } -%>
6465
public class <%- toPascalCase(collection.name) %>: Codable {
6566
<% for (const attribute of collection.attributes) { -%>
66-
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %>
67+
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>
6768
<% } %>
6869
enum CodingKeys: String, CodingKey {
6970
<% for (const attribute of collection.attributes) { -%>
@@ -73,7 +74,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
7374

7475
public init(
7576
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
76-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
77+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7778
<% } -%>
7879
) {
7980
<% for (const attribute of collection.attributes) { -%>
@@ -86,9 +87,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
8687

8788
<% for (const attribute of collection.attributes) { -%>
8889
<% if (!(!attribute.required && attribute.default === null)) { -%>
89-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
90+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute, collections).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9091
<% } else { -%>
91-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
92+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute, collections).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9293
<% } -%>
9394
<% } -%>
9495
}

0 commit comments

Comments
 (0)