Skip to content

Commit 15e91ee

Browse files
Merge pull request #48 from themooks/master
[DEVTOOLING-1225] Fix management of enum constants starting with a digit for Java SDK
2 parents 1b3667f + 828a214 commit 15e91ee

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PureCloudJavaClientCodegen.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,33 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
203203
}
204204
}
205205
}
206+
} else if (cp.isArray && cp.items != null && cp.items.isEnum && cp.items.allowableValues != null) {
207+
Object valuesObject = cp.items.allowableValues.get("values");
208+
if (valuesObject != null) {
209+
ArrayList valuesArray = (ArrayList) valuesObject;
210+
if (valuesArray.get(0) instanceof Integer) {
211+
// Integer enum type
212+
valuesArray.add(0, -1);
213+
Object enumVarsObject = cp.items.allowableValues.get("enumVars");
214+
ArrayList enumVarsArray = (ArrayList) enumVarsObject;
215+
HashMap<String, String> newItem = new HashMap<>();
216+
newItem.put("name", "OUTDATEDSDKVERSION");
217+
newItem.put("value", toEnumValue("-1", "Integer"));
218+
enumVarsArray.add(0, newItem);
219+
} else {
220+
// String enum type
221+
if (!valuesArray.get(0).equals("OutdatedSdkVersion")) {
222+
valuesArray.add(0, "OutdatedSdkVersion");
223+
Object enumVarsObject = cp.items.allowableValues.get("enumVars");
224+
ArrayList enumVarsArray = (ArrayList) enumVarsObject;
225+
HashMap<String, String> newItem = new HashMap<>();
226+
newItem.put("name", "OUTDATEDSDKVERSION");
227+
newItem.put("isString", "true");
228+
newItem.put("value", toEnumValue("OutdatedSdkVersion", "String"));
229+
enumVarsArray.add(0, newItem);
230+
}
231+
}
232+
}
206233
}
207234
vars.add(cp);
208235
}

modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/PrefixNumberWithValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public void execute(Template.Fragment fragment, Writer writer) throws IOExceptio
3535
line = value + line;
3636
}
3737
} catch (Exception e) {
38+
// Check if string starts with a digit
39+
if (Character.isDigit(line.charAt(0))) {
40+
// Add prefix
41+
line = value + line;
42+
}
3843
// NOOP
3944
}
4045
}

0 commit comments

Comments
 (0)