Skip to content

Commit 565841f

Browse files
committed
add equals to reserved keywords and escape method names
1 parent f87325c commit 565841f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.generator/src/generator/formatter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"do",
2424
"else",
2525
"enum",
26+
"equals",
2627
"extends",
2728
"false",
2829
"final",
@@ -74,6 +75,11 @@
7475
"\\": "\\\\",
7576
}
7677

78+
METHOD_KEYWORDS = {
79+
"getClass",
80+
"setClass",
81+
}
82+
7783

7884
PATTERN_DOUBLE_UNDERSCORE = re.compile(r"__+")
7985
PATTERN_LEADING_ALPHA = re.compile(r"(.)([A-Z][a-z0-9]+)")
@@ -125,6 +131,14 @@ def untitle_case(value):
125131
def upperfirst(value):
126132
return value[0].upper() + value[1:]
127133

134+
def escape_method_reserved_names(method_name):
135+
"""
136+
Escape reserved language keywords for method names like getClass, setClass, isClass, etc.
137+
"""
138+
if method_name in METHOD_KEYWORDS:
139+
return f"{method_name}Attribute"
140+
return method_name
141+
128142

129143
def schema_name(schema):
130144
if not schema:

.generator/src/generator/templates/modelSimple.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends
216216
{%- if schema.additionalProperties is defined and schema.additionalProperties is not false %}{%- if schema.additionalProperties.nullable %}content = JsonInclude.Include.ALWAYS,{%- endif %}{%- endif %}
217217
value = JsonInclude.Include.{%- if isRequired %}ALWAYS{%- else %}USE_DEFAULTS{%- endif %})
218218
{%- endif %}
219-
public {{ dataType }} get{{ attr|camel_case|upperfirst }}() {
219+
public {{ dataType }} get{{ attr|camel_case|upperfirst|escape_reserved_keyword }}() {
220220
{%- if not isRequired and isNullable %}
221221
{%- if schema.get("readOnly", False) %}
222222

@@ -247,7 +247,7 @@ public class {{ name }} {%- if model.get("x-generate-alias-as-model") %} extends
247247
{%- endif %}
248248

249249
{%- if not schema.get("readOnly", False) %}
250-
public void set{{ attr|camel_case|upperfirst }}({{ dataType }} {{ variableName }}) {
250+
public void set{{ attr|camel_case|upperfirst|escape_reserved_keyword }}({{ dataType }} {{ variableName }}) {
251251
{%- if schema.enum is defined %}
252252
if (!{{ variableName }}.isValid()) {
253253
this.unparsed = true;

0 commit comments

Comments
 (0)