Skip to content

Commit d1599fc

Browse files
Merge pull request #1094 from appwrite/types-generation-fixes
fix: types generation errors
2 parents d8c7bb2 + ad0882b commit d1599fc

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import '<%- attribute.relatedCollection.toLowerCase() %>.dart';
5252
<% if (attribute.format === 'enum') { -%>
5353
enum <%- toPascalCase(attribute.key) %> {
5454
<% for (const element of attribute.elements) { -%>
55-
<%- element %>,
55+
<%- toSnakeCase(element) %>,
5656
<% } -%>
5757
}
5858

@@ -78,7 +78,7 @@ class <%= toPascalCase(collection.name) %> {
7878
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
7979
<% } else { -%>
8080
<% if (!attribute.required) { -%>
81-
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
81+
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull() : null<% } else { -%>
8282
<%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
8383
<% } -%>
8484
<% } else { -%>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Java extends LanguageMeta {
4444
import java.util.*;
4545
<% for (const attribute of collection.attributes) { -%>
4646
<% if (attribute.type === 'relationship') { -%>
47-
import <%- toPascalCase(attribute.relatedCollection) %>;
47+
import io.appwrite.models.<%- toPascalCase(attribute.relatedCollection) %>;
4848

4949
<% } -%>
5050
<% } -%>
@@ -54,7 +54,7 @@ public class <%- toPascalCase(collection.name) %> {
5454

5555
public enum <%- toPascalCase(attribute.key) %> {
5656
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
57-
<%- element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
57+
<%- toSnakeCase(element) %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
5858
<% } -%>
5959
}
6060

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import <%- toPascalCase(attribute.relatedCollection) %>
5454
<% if (attribute.format === 'enum') { -%>
5555
enum class <%- toPascalCase(attribute.key) %> {
5656
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
57-
<%- element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
57+
<%- toUpperSnakeCase(element) %><%- index < attribute.elements.length - 1 ? ',' : '' %>
5858
<% } -%>
5959
}
6060

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ public class <%- toPascalCase(collection.name) %>: Codable {
116116
return <%- toPascalCase(collection.name) %>(
117117
<% for (const attribute of collection.attributes) { -%>
118118
<% if (attribute.type === 'relationship') { -%>
119+
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
120+
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [<%- toPascalCase(attribute.relatedCollection) %>]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
121+
<% } else { -%>
119122
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
123+
<% } -%>
120124
<% } else if (attribute.array) { -%>
121125
<% if (attribute.type === 'string') { -%>
122126
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
@@ -130,8 +134,10 @@ public class <%- toPascalCase(collection.name) %>: Codable {
130134
<%- toCamelCase(attribute.key) %>: (map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [[String: Any]])<% if (!attribute.required) { %>?<% } %>.map { <%- toPascalCase(attribute.type) %>.from(map: $0) }<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
131135
<% } -%>
132136
<% } else { -%>
133-
<% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime' || attribute.type === 'enum') { -%>
137+
<% if ((attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') && attribute.format !== 'enum') { -%>
134138
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
139+
<% } else if (attribute.type === 'string' && attribute.format === 'enum') { -%>
140+
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.key) %>(rawValue: map["<%- attribute.key %>"] as! String)!<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
135141
<% } else if (attribute.type === 'integer') { -%>
136142
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
137143
<% } else if (attribute.type === 'float') { -%>

0 commit comments

Comments
 (0)