Skip to content

Commit c9100c2

Browse files
committed
fix: type generation for enums by prefixing table name
1 parent cd71267 commit c9100c2

File tree

7 files changed

+46
-46
lines changed

7 files changed

+46
-46
lines changed

templates/cli/lib/type-generation/languages/csharp.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 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') {

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
`;

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

Lines changed: 9 additions & 9 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, collections) {
6+
getType(attribute, collections, collectionName) {
77
if (attribute.array) {
88
return "array";
99
}
@@ -14,7 +14,7 @@ class PHP extends LanguageMeta {
1414
case AttributeType.DATETIME:
1515
type = "string";
1616
if (attribute.format === AttributeType.ENUM) {
17-
type = LanguageMeta.toPascalCase(attribute.key);
17+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1818
}
1919
break;
2020
case AttributeType.INTEGER:
@@ -60,25 +60,25 @@ use Appwrite\\Models\\<%- toPascalCase(collections.find(c => c.$id === attribute
6060
<% } -%>
6161
<% for (const attribute of collection.attributes) { -%>
6262
<% if (attribute.format === 'enum') { -%>
63-
enum <%- toPascalCase(attribute.key) %>: string {
63+
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>: string {
6464
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
65-
case <%- strict ? toUpperSnakeCase(element) : element %> = '<%- element %>';
65+
case <%- toUpperSnakeCase(element) %> = '<%- element %>';
6666
<% } -%>
6767
}
6868
6969
<% } -%>
7070
<% } -%>
7171
class <%- toPascalCase(collection.name) %> {
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 function __construct(
7777
<% for (const attribute of collection.attributes ){ -%>
7878
<% if (attribute.required) { -%>
79-
<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
79+
<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8080
<% } else { -%>
81-
?<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
81+
?<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8282
<% } -%>
8383
<% } -%>
8484
) {
@@ -88,11 +88,11 @@ class <%- toPascalCase(collection.name) %> {
8888
}
8989
9090
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
91-
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections) %> {
91+
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections, collection.name) %> {
9292
return $this-><%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9393
}
9494
95-
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
95+
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
9696
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9797
}
9898
<% if (index < collection.attributes.length - 1) { %>

templates/cli/lib/type-generation/languages/swift.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 Swift 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:
@@ -53,7 +53,7 @@ class Swift extends LanguageMeta {
5353

5454
<% for (const attribute of collection.attributes) { -%>
5555
<% if (attribute.format === 'enum') { -%>
56-
public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
56+
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
5757
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
5858
case <%- strict ? toCamelCase(element) : element %> = "<%- element %>"
5959
<% } -%>
@@ -63,7 +63,7 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
6363
<% } -%>
6464
public class <%- toPascalCase(collection.name) %>: Codable {
6565
<% for (const attribute of collection.attributes) { -%>
66-
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %>
66+
public let <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections, collection.name) %>
6767
<% } %>
6868
enum CodingKeys: String, CodingKey {
6969
<% for (const attribute of collection.attributes) { -%>
@@ -73,7 +73,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
7373

7474
public init(
7575
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
76-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
76+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections, collection.name) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7777
<% } -%>
7878
) {
7979
<% for (const attribute of collection.attributes) { -%>
@@ -86,9 +86,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {
8686

8787
<% for (const attribute of collection.attributes) { -%>
8888
<% if (!(!attribute.required && attribute.default === null)) { -%>
89-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute, collections).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
89+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decode(<%- getType(attribute, collections, collection.name).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9090
<% } else { -%>
91-
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute, collections).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
91+
self.<%- strict ? toCamelCase(attribute.key) : attribute.key %> = try container.decodeIfPresent(<%- getType(attribute, collections, collection.name).replace('?', '') %>.self, forKey: .<%- strict ? toCamelCase(attribute.key) : attribute.key %>)
9292
<% } -%>
9393
<% } -%>
9494
}
@@ -144,7 +144,7 @@ public class <%- toPascalCase(collection.name) %>: Codable {
144144
<% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
145145
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (index < collection.attributes.length - 1) { %>,<% } %>
146146
<% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
147-
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
147+
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (index < collection.attributes.length - 1) { %>,<% } %>
148148
<% } else if (attribute.type === 'integer') { -%>
149149
<%- strict ? toCamelCase(attribute.key) : attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (index < collection.attributes.length - 1) { %>,<% } %>
150150
<% } else if (attribute.type === 'float') { -%>

0 commit comments

Comments
 (0)