Skip to content

Commit 5ffd5fa

Browse files
committed
chore: finish enum for php ts and swift
1 parent d9ca85a commit 5ffd5fa

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class PHP extends LanguageMeta {
1212
case AttributeType.STRING:
1313
case AttributeType.EMAIL:
1414
case AttributeType.DATETIME:
15-
case AttributeType.ENUM:
1615
type = "string";
16+
if (attribute.format === AttributeType.ENUM) {
17+
type = LanguageMeta.toPascalCase(attribute.key);
18+
}
1719
break;
1820
case AttributeType.INTEGER:
1921
type = "int";
@@ -47,6 +49,16 @@ namespace Appwrite\\Models;
4749
<% if (attribute.type === 'relationship' && !(attribute.relationType === 'manyToMany') && !(attribute.relationType === 'oneToMany' && attribute.side === 'parent')) { -%>
4850
use Appwrite\\Models\\<%- toPascalCase(attribute.relatedCollection) %>;
4951
52+
<% } -%>
53+
<% } -%>
54+
<% for (const attribute of collection.attributes) { -%>
55+
<% if (attribute.format === 'enum') { -%>
56+
enum <%- toPascalCase(attribute.key) %> {
57+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
58+
case <%- element.toUpperCase() %> = '<%- element %>';
59+
<% } -%>
60+
}
61+
5062
<% } -%>
5163
<% } -%>
5264
class <%- toPascalCase(collection.name) %> {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class Swift extends LanguageMeta {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
12-
case AttributeType.ENUM:
1312
type = "String";
13+
if (attribute.format === AttributeType.ENUM) {
14+
type = LanguageMeta.toPascalCase(attribute.key);
15+
}
1416
break;
1517
case AttributeType.INTEGER:
1618
type = "Int";
@@ -42,6 +44,16 @@ class Swift extends LanguageMeta {
4244
getTemplate() {
4345
return `import Foundation
4446

47+
<% for (const attribute of collection.attributes) { -%>
48+
<% if (attribute.format === 'enum') { -%>
49+
public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
50+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
51+
case <%- element %> = "<%- element %>"
52+
<% } -%>
53+
}
54+
55+
<% } -%>
56+
<% } -%>
4557
public class <%- toPascalCase(collection.name) %>: Codable {
4658
<% for (const attribute of collection.attributes) { -%>
4759
public let <%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ class TypeScript extends LanguageMeta {
1212
case AttributeType.STRING:
1313
case AttributeType.EMAIL:
1414
case AttributeType.DATETIME:
15-
case AttributeType.ENUM:
1615
case AttributeType.IP:
1716
case AttributeType.___URL:
1817
type = "string";
18+
if (attribute.format === AttributeType.ENUM) {
19+
type = LanguageMeta.toPascalCase(attribute.key);
20+
}
1921
break;
2022
case AttributeType.INTEGER:
2123
type = "number";
@@ -64,6 +66,18 @@ class TypeScript extends LanguageMeta {
6466

6567
getTemplate() {
6668
return `import { Models } from '${this._getAppwriteDependency()}';
69+
70+
<% for (const collection of collections) { -%>
71+
<% for (const attribute of collection.attributes) { -%>
72+
<% if (attribute.format === 'enum') { -%>
73+
export enum <%- toPascalCase(attribute.key) %> {
74+
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
75+
<%- element.toUpperCase() %> = "<%- element %>",
76+
<% } -%>
77+
}
78+
<% } -%>
79+
<% } -%>
80+
<% } -%>
6781
<% for (const collection of collections) { %>
6882
export type <%- toPascalCase(collection.name) %> = Models.Document & {
6983
<% for (const attribute of collection.attributes) { -%>

0 commit comments

Comments
 (0)