mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 12:10:54 +00:00
Fix nim compilation in case a edge case of a schema with enum (#20780)
If enum constraint contains one value which is not a valid nim identifier, we must surround this identifier with backtick.
This commit is contained in:
parent
78b54b9283
commit
13c95f1dd2
@ -355,15 +355,21 @@ public class NimClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidIdentifier(String identifier) {
|
||||
//see https://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-amp-keywords
|
||||
return identifier.matches("^(?:[A-Z]|[a-z]|[\\x80-\\xff])(_?(?:[A-Z]|[a-z]|[\\x80-\\xff]|[0-9]))*$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
name = name.replace(" ", "_");
|
||||
name = StringUtils.camelize(name);
|
||||
|
||||
if (name.matches("\\d.*")) { // starts with number
|
||||
return "`" + name + "`";
|
||||
} else {
|
||||
// starts with number or contains any character not allowed,see
|
||||
if (isValidIdentifier(name)) {
|
||||
return name;
|
||||
} else {
|
||||
return "`" + name + "`";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user