Skip to content

Commit 0f60155

Browse files
committed
feat: add support for enum
1 parent 47e51e1 commit 0f60155

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ class Dart 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";
@@ -23,7 +25,7 @@ class Dart extends LanguageMeta {
2325
break;
2426
case AttributeType.RELATIONSHIP:
2527
type = LanguageMeta.toPascalCase(attribute.relatedCollection);
26-
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') (attribute.relationType === 'manyToOne' && attribute.side === 'child') || || attribute.relationType === 'manyToMany') {
28+
if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') {
2729
type = `List<${type}>`;
2830
}
2931
break;
@@ -44,6 +46,16 @@ class Dart extends LanguageMeta {
4446
<% if (attribute.type === 'relationship') { -%>
4547
import '<%- attribute.relatedCollection.toLowerCase() %>.dart';
4648

49+
<% } -%>
50+
<% } -%>
51+
<% for (const attribute of collection.attributes) { -%>
52+
<% if (attribute.format === 'enum') { -%>
53+
enum <%- toPascalCase(attribute.key) %> {
54+
<% for (const element of attribute.elements) { -%>
55+
<%- toPascalCase(element) %>,
56+
<% } -%>
57+
}
58+
4759
<% } -%>
4860
<% } -%>
4961
class <%= toPascalCase(collection.name) %> {

0 commit comments

Comments
 (0)