File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed
templates/cli/lib/type-generation/languages Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,10 @@ class PHP extends LanguageMeta {
12
12
case AttributeType.STRING:
13
13
case AttributeType.EMAIL:
14
14
case AttributeType.DATETIME:
15
- case AttributeType.ENUM:
16
15
type = "string";
16
+ if (attribute.format === AttributeType.ENUM) {
17
+ type = LanguageMeta.toPascalCase(attribute.key);
18
+ }
17
19
break;
18
20
case AttributeType.INTEGER:
19
21
type = "int";
@@ -47,6 +49,16 @@ namespace Appwrite\\Models;
47
49
< % if (attribute . type === ' relationship' && ! (attribute . relationType === ' manyToMany' ) && ! (attribute . relationType === ' oneToMany' && attribute . side === ' parent' )) { -% >
48
50
use Appwrite\\Models\\<%- toPascalCase(attribute.relatedCollection) %>;
49
51
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
+
50
62
< % } -% >
51
63
< % } -% >
52
64
class < %- toPascalCase(collection . name ) % > {
Original file line number Diff line number Diff line change @@ -9,8 +9,10 @@ class Swift extends LanguageMeta {
9
9
case AttributeType.STRING:
10
10
case AttributeType.EMAIL:
11
11
case AttributeType.DATETIME:
12
- case AttributeType.ENUM:
13
12
type = "String";
13
+ if (attribute.format === AttributeType.ENUM) {
14
+ type = LanguageMeta.toPascalCase(attribute.key);
15
+ }
14
16
break;
15
17
case AttributeType.INTEGER:
16
18
type = "Int";
@@ -42,6 +44,16 @@ class Swift extends LanguageMeta {
42
44
getTemplate() {
43
45
return `import Foundation
44
46
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
+ <% } -%>
45
57
public class <% - toPascalCase(collection.name) %> : Codable {
46
58
<% for (const attribute of collection.attributes) { -%>
47
59
public let <% - toCamelCase(attribute.key) %> : <% - getType(attribute) %>
Original file line number Diff line number Diff line change @@ -12,10 +12,12 @@ class TypeScript extends LanguageMeta {
12
12
case AttributeType.STRING:
13
13
case AttributeType.EMAIL:
14
14
case AttributeType.DATETIME:
15
- case AttributeType.ENUM:
16
15
case AttributeType.IP:
17
16
case AttributeType.___URL:
18
17
type = "string";
18
+ if (attribute.format === AttributeType.ENUM) {
19
+ type = LanguageMeta.toPascalCase(attribute.key);
20
+ }
19
21
break;
20
22
case AttributeType.INTEGER:
21
23
type = "number";
@@ -64,6 +66,18 @@ class TypeScript extends LanguageMeta {
64
66
65
67
getTemplate() {
66
68
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
+ <% } -%>
67
81
<% for (const collection of collections) { %>
68
82
export type <% - toPascalCase(collection.name) %> = Models.Document & {
69
83
<% for (const attribute of collection.attributes) { -%>
You can’t perform that action at this time.
0 commit comments