File tree 1 file changed +9
-3
lines changed
modules/openapi-generator/src/main/java/org/openapitools/codegen/languages
1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -355,15 +355,21 @@ public String toEnumName(CodegenProperty property) {
355
355
}
356
356
}
357
357
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
+
358
363
@ Override
359
364
public String toEnumVarName (String name , String datatype ) {
360
365
name = name .replace (" " , "_" );
361
366
name = StringUtils .camelize (name );
362
367
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 )) {
366
370
return name ;
371
+ } else {
372
+ return "`" + name + "`" ;
367
373
}
368
374
}
369
375
You can’t perform that action at this time.
0 commit comments