Skip to content

fix: remove conversion of attribute keys to camel case #1092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions templates/cli/lib/type-generation/languages/dart.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ enum <%- toPascalCase(attribute.key) %> {
<% } -%>
class <%= toPascalCase(collection.name) %> {
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<%- getType(attribute) %> <%= toCamelCase(attribute.key) %>;
<%- getType(attribute) %> <%- attribute.key %>;
<% } -%>

<%= toPascalCase(collection.name) %>({
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<% if (attribute.required) { %>required <% } %>this.<%= toCamelCase(attribute.key) %>,
<% if (attribute.required) { %>required <% } %>this.<%- attribute.key %>,
<% } -%>
});

factory <%= toPascalCase(collection.name) %>.fromMap(Map<String, dynamic> map) {
return <%= toPascalCase(collection.name) %>(
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<%= toCamelCase(attribute.key) %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
<%- attribute.key %>: <% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime') { -%>
<% if (attribute.format === 'enum') { -%>
<% if (attribute.array) { -%>
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% if (!attribute.required) { %> ?? []<% } -%>
Expand Down Expand Up @@ -124,18 +124,18 @@ map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.relatedCollecti
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
"<%= attribute.key %>": <% if (attribute.type === 'relationship') { -%>
<% if ((attribute.relationType === 'oneToMany' && attribute.side === 'parent') || (attribute.relationType === 'manyToOne' && attribute.side === 'child') || attribute.relationType === 'manyToMany') { -%>
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
<%- attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.toMap()).toList()<% if (!attribute.required) { %> ?? []<% } -%>
<% } else { -%>
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
<%- attribute.key %><% if (!attribute.required) { %>?<% } %>.toMap()<% if (!attribute.required) { %> ?? {}<% } -%>
<% } -%>
<% } else if (attribute.format === 'enum') { -%>
<% if (attribute.array) { -%>
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
<%- attribute.key %><% if (!attribute.required) { %>?<% } %>.map((e) => e.name).toList()<% if (!attribute.required) { %> ?? []<% } -%>
<% } else { -%>
<%= toCamelCase(attribute.key) %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
<%- attribute.key %><% if (!attribute.required) { %>?<% } %>.name<% if (!attribute.required) { %> ?? null<% } -%>
<% } -%>
<% } else { -%>
<%= toCamelCase(attribute.key) -%>
<%- attribute.key -%>
<% } -%>,
<% } -%>
};
Expand Down
18 changes: 9 additions & 9 deletions templates/cli/lib/type-generation/languages/java.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,29 @@ public class <%- toPascalCase(collection.name) %> {
<% } -%>
<% } -%>
<% for (const attribute of collection.attributes) { -%>
private <%- getType(attribute) %> <%- toCamelCase(attribute.key) %>;
private <%- getType(attribute) %> <%- attribute.key %>;
<% } -%>

public <%- toPascalCase(collection.name) %>() {
}

public <%- toPascalCase(collection.name) %>(
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
<%- getType(attribute) %> <%= toCamelCase(attribute.key) %><%- index < collection.attributes.length - 1 ? ',' : '' %>
<%- getType(attribute) %> <%- attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
<% } -%>
) {
<% for (const attribute of collection.attributes) { -%>
this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %>;
this.<%- attribute.key %> = <%- attribute.key %>;
<% } -%>
}

<% for (const attribute of collection.attributes) { -%>
public <%- getType(attribute) %> get<%- toPascalCase(attribute.key) %>() {
return <%= toCamelCase(attribute.key) %>;
return <%- attribute.key %>;
}

public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> <%= toCamelCase(attribute.key) %>) {
this.<%= toCamelCase(attribute.key) %> = <%= toCamelCase(attribute.key) %>;
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> <%- attribute.key %>) {
this.<%- attribute.key %> = <%- attribute.key %>;
}

<% } -%>
Expand All @@ -92,20 +92,20 @@ public class <%- toPascalCase(collection.name) %> {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
<%- toPascalCase(collection.name) %> that = (<%- toPascalCase(collection.name) %>) obj;
return <% collection.attributes.forEach((attr, index) => { %>Objects.equals(<%= toCamelCase(attr.key) %>, that.<%= toCamelCase(attr.key) %>)<% if (index < collection.attributes.length - 1) { %> &&
return <% collection.attributes.forEach((attr, index) => { %>Objects.equals(<%- attr.key %>, that.<%- attr.key %>)<% if (index < collection.attributes.length - 1) { %> &&
<% } }); %>;
}

@Override
public int hashCode() {
return Objects.hash(<%= collection.attributes.map(attr => toCamelCase(attr.key)).join(', ') %>);
return Objects.hash(<%- collection.attributes.map(attr => attr.key).join(', ') %>);
}

@Override
public String toString() {
return "<%- toPascalCase(collection.name) %>{" +
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
"<%= toCamelCase(attribute.key) %>=" + <%= toCamelCase(attribute.key) %> +
"<%- attribute.key %>=" + <%- attribute.key %> +
<% } -%>
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class JavaScript extends LanguageMeta {
/**
* @typedef {Object} <%- toPascalCase(collection.name) %>
<% for (const attribute of collection.attributes) { -%>
* @property {<%- getType(attribute) %>} <%- toCamelCase(attribute.key) %>
* @property {<%- getType(attribute) %>} <%- attribute.key %>
<% } -%>
*/

Expand Down
2 changes: 1 addition & 1 deletion templates/cli/lib/type-generation/languages/kotlin.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum class <%- toPascalCase(attribute.key) %> {
<% } -%>
data class <%- toPascalCase(collection.name) %>(
<% for (const attribute of collection.attributes) { -%>
val <%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>,
val <%- attribute.key %>: <%- getType(attribute) %>,
<% } -%>
)`;
}
Expand Down
14 changes: 7 additions & 7 deletions templates/cli/lib/type-generation/languages/php.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,30 @@ enum <%- toPascalCase(attribute.key) %> {
<% } -%>
class <%- toPascalCase(collection.name) %> {
<% for (const attribute of collection.attributes ){ -%>
private <%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>;
private <%- getType(attribute) %> $<%- attribute.key %>;
<% } -%>

public function __construct(
<% for (const attribute of collection.attributes ){ -%>
<% if (attribute.required) { -%>
<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<%- getType(attribute).replace('|null', '') %> $<%- attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<% } else { -%>
?<%- getType(attribute).replace('|null', '') %> $<%- toCamelCase(attribute.key) %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
?<%- getType(attribute).replace('|null', '') %> $<%- attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
<% } -%>
<% } -%>
) {
<% for (const attribute of collection.attributes ){ -%>
$this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
$this-><%- attribute.key %> = $<%- attribute.key %>;
<% } -%>
}

<% for (const attribute of collection.attributes ){ -%>
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute) %> {
return $this-><%- toCamelCase(attribute.key) %>;
return $this-><%- attribute.key %>;
}

public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- toCamelCase(attribute.key) %>): void {
$this-><%- toCamelCase(attribute.key) %> = $<%- toCamelCase(attribute.key) %>;
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute) %> $<%- attribute.key %>): void {
$this-><%- attribute.key %> = $<%- attribute.key %>;
}
<% } -%>
}`;
Expand Down
44 changes: 22 additions & 22 deletions templates/cli/lib/type-generation/languages/swift.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ public enum <%- toPascalCase(attribute.key) %>: String, Codable, CaseIterable {
<% } -%>
public class <%- toPascalCase(collection.name) %>: Codable {
<% for (const attribute of collection.attributes) { -%>
public let <%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>
public let <%- attribute.key %>: <%- getType(attribute) %>
<% } %>
enum CodingKeys: String, CodingKey {
<% for (const attribute of collection.attributes) { -%>
case <%- toCamelCase(attribute.key) %> = "<%- attribute.key %>"
case <%- attribute.key %> = "<%- attribute.key %>"
<% } -%>
}

init(
<% for (const attribute of collection.attributes) { -%>
<%- toCamelCase(attribute.key) %>: <%- getType(attribute) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: <%- getType(attribute) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } -%>
) {
<% for (const attribute of collection.attributes) { -%>
self.<%- toCamelCase(attribute.key) %> = <%- toCamelCase(attribute.key) %>
self.<%- attribute.key %> = <%- attribute.key %>
<% } -%>
}

Expand All @@ -79,9 +79,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {

<% for (const attribute of collection.attributes) { -%>
<% if (attribute.required) { -%>
self.<%- toCamelCase(attribute.key) %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- toCamelCase(attribute.key) %>)
self.<%- attribute.key %> = try container.decode(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- attribute.key %>)
<% } else { -%>
self.<%- toCamelCase(attribute.key) %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- toCamelCase(attribute.key) %>)
self.<%- attribute.key %> = try container.decodeIfPresent(<%- getType(attribute).replace('?', '') %>.self, forKey: .<%- attribute.key %>)
<% } -%>
<% } -%>
}
Expand All @@ -91,9 +91,9 @@ public class <%- toPascalCase(collection.name) %>: Codable {

<% for (const attribute of collection.attributes) { -%>
<% if (attribute.required) { -%>
try container.encode(<%- toCamelCase(attribute.key) %>, forKey: .<%- toCamelCase(attribute.key) %>)
try container.encode(<%- attribute.key %>, forKey: .<%- attribute.key %>)
<% } else { -%>
try container.encodeIfPresent(<%- toCamelCase(attribute.key) %>, forKey: .<%- toCamelCase(attribute.key) %>)
try container.encodeIfPresent(<%- attribute.key %>, forKey: .<%- attribute.key %>)
<% } -%>
<% } -%>
}
Expand All @@ -102,11 +102,11 @@ public class <%- toPascalCase(collection.name) %>: Codable {
return [
<% for (const attribute of collection.attributes) { -%>
<% if (attribute.type === 'relationship') { -%>
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
"<%- attribute.key %>": <%- attribute.key %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.array && attribute.type !== 'string' && attribute.type !== 'integer' && attribute.type !== 'float' && attribute.type !== 'boolean') { -%>
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %>?.map { $0.toMap() } as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
"<%- attribute.key %>": <%- attribute.key %>?.map { $0.toMap() } as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else { -%>
"<%- attribute.key %>": <%- toCamelCase(attribute.key) %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
"<%- attribute.key %>": <%- attribute.key %> as Any<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } -%>
<% } -%>
]
Expand All @@ -116,30 +116,30 @@ public class <%- toPascalCase(collection.name) %>: Codable {
return <%- toPascalCase(collection.name) %>(
<% for (const attribute of collection.attributes) { -%>
<% if (attribute.type === 'relationship') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> <%- toPascalCase(attribute.relatedCollection) %><% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.array) { -%>
<% if (attribute.type === 'string') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [String]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'integer') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Int]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'float') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Double]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'boolean') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> [Bool]<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else { -%>
<%- 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]) { %>,<% } %>
<%- 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]) { %>,<% } %>
<% } -%>
<% } else { -%>
<% if (attribute.type === 'string' || attribute.type === 'email' || attribute.type === 'datetime' || attribute.type === 'enum') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> String<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'integer') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Int<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'float') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Double<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else if (attribute.type === 'boolean') { -%>
<%- toCamelCase(attribute.key) %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: map["<%- attribute.key %>"] as<% if (!attribute.required) { %>?<% } else { %>!<% } %> Bool<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } else { -%>
<%- toCamelCase(attribute.key) %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<%- attribute.key %>: <%- toPascalCase(attribute.type) %>.from(map: map["<%- attribute.key %>"] as! [String: Any])<% if (attribute !== collection.attributes[collection.attributes.length - 1]) { %>,<% } %>
<% } -%>
<% } -%>
<% } -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ export enum <%- toPascalCase(attribute.key) %> {
<%- element.toUpperCase() %> = "<%- element %>",
<% } -%>
}

<% } -%>
<% } -%>
<% } -%>
<% for (const collection of collections) { %>
<% for (const collection of collections) { -%>
export type <%- toPascalCase(collection.name) %> = Models.Document & {
<% for (const attribute of collection.attributes) { -%>
<%- toCamelCase(attribute.key) %>: <%- getType(attribute) %>;
<%- attribute.key %>: <%- getType(attribute) %>;
<% } -%>
}

<% } %>`;
}

Expand Down