Skip to content

Commit c2d3e6b

Browse files
committed
Fix nim compilation in case a edge case of a schema with enum
If enum constraint contains one value which is not a valid nim identifier, we must surround this identifier with backtick.
1 parent 0f13dfe commit c2d3e6b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,21 @@ public String toEnumName(CodegenProperty property) {
355355
}
356356
}
357357

358+
private boolean isValidIdentifier(String identifier) {
359+
//see https://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-amp-keywords
360+
return identifier.matches("^(?:[A-Z]|[a-z]|[\\x80-\\xff])(_?(?:[A-Z]|[a-z]|[\\x80-\\xff]|[0-9]))*$");
361+
}
362+
358363
@Override
359364
public String toEnumVarName(String name, String datatype) {
360365
name = name.replace(" ", "_");
361366
name = StringUtils.camelize(name);
362367

363-
if (name.matches("\\d.*")) { // starts with number
364-
return "`" + name + "`";
365-
} else {
368+
// starts with number or contains any character not allowed,see
369+
if (isValidIdentifier(name)) {
366370
return name;
371+
} else {
372+
return "`" + name + "`";
367373
}
368374
}
369375

0 commit comments

Comments
 (0)