@@ -145,7 +145,7 @@ public String escapeReservedWord(String name) {
145145
146146 @ Override
147147 public String toVarName (String name ) {
148-
148+
149149 // replace - with _ e.g. created-at => created_at
150150 name = sanitizeName (name );
151151
@@ -267,10 +267,10 @@ public String getTypeDeclaration(Schema p) {
267267 // the type.
268268 String openAPIType = getSchemaType (p );
269269 String ref = p .get$ref ();
270- if (ref != null && !ref .isEmpty ()) {
270+ if (ref != null && !ref .isEmpty ()) {
271271 String tryRefV2 = "#/definitions/" + openAPIType ;
272272 String tryRefV3 = "#/components/schemas/" + openAPIType ;
273- if (ref .equals (tryRefV2 ) || ref .equals (tryRefV3 )) {
273+ if (ref .equals (tryRefV2 ) || ref .equals (tryRefV3 )) {
274274 return toModelName (openAPIType );
275275 }
276276 }
@@ -296,7 +296,7 @@ public String getSchemaType(Schema p) {
296296 String ref = p .get$ref ();
297297 String type = null ;
298298
299- if (ref != null && !ref .isEmpty ()) {
299+ if (ref != null && !ref .isEmpty ()) {
300300 type = openAPIType ;
301301 } else if (typeMapping .containsKey (openAPIType )) {
302302 type = typeMapping .get (openAPIType );
@@ -570,8 +570,10 @@ public String toEnumVarName(String name, String datatype) {
570570 enumName = enumName .replaceFirst ("^_" , "" );
571571 enumName = enumName .replaceFirst ("_$" , "" );
572572
573- if (isReservedWord (enumName ) || enumName . matches ( " \\ d.*" )) { // reserved word or starts with number
573+ if (isReservedWord (enumName )) { // reserved word
574574 return escapeReservedWord (enumName );
575+ } else if (enumName .matches ("\\ d.*" )) { // starts with a number
576+ return "_" + enumName ;
575577 } else {
576578 return enumName ;
577579 }
0 commit comments