@@ -458,10 +458,13 @@ public CodegenModel fromModel(String name, Schema schema) {
458458 name = normalizeSchemaName (name );
459459 CodegenModel mdl = super .fromModel (name , schema );
460460
461- // Detect integer enums - check both the schema type and the dataType
461+ // Detect numeric enums - check both the schema type and the dataType
462+ // Note: "number" type in OpenAPI can include integer values in enums
462463 if (mdl .isEnum ) {
463464 String schemaType = schema != null ? schema .getType () : null ;
464- if ("integer" .equals (schemaType ) || "int" .equals (mdl .dataType ) || "int64" .equals (mdl .dataType )) {
465+ if ("integer" .equals (schemaType ) || "number" .equals (schemaType ) ||
466+ "int" .equals (mdl .dataType ) || "int64" .equals (mdl .dataType ) ||
467+ "float" .equals (mdl .dataType ) || "float64" .equals (mdl .dataType )) {
465468 mdl .vendorExtensions .put ("x-is-integer-enum" , true );
466469 }
467470 }
@@ -606,22 +609,38 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
606609 return objs ;
607610 }
608611
612+ /**
613+ * Resolve a schema reference to its target schema.
614+ * This is needed to properly detect nested maps/arrays when the schema is a $ref.
615+ */
616+ private Schema resolveSchema (Schema schema ) {
617+ if (schema != null && schema .get$ref () != null ) {
618+ Schema resolved = ModelUtils .getReferencedSchema (this .openAPI , schema );
619+ return resolved != null ? resolved : schema ;
620+ }
621+ return schema ;
622+ }
623+
609624 @ Override
610625 public String getTypeDeclaration (Schema p ) {
611- if (ModelUtils .isArraySchema (p )) {
612- Schema inner = ModelUtils .getSchemaItems (p );
626+ // Resolve the schema to check for nested maps/arrays - refs that point to map/array schemas
627+ Schema resolved = resolveSchema (p );
628+
629+ if (ModelUtils .isArraySchema (resolved )) {
630+ Schema inner = ModelUtils .getSchemaItems (resolved );
613631 if (inner == null ) {
614632 return null ;
615633 }
616634 return "seq[" + getTypeDeclaration (inner ) + "]" ;
617- } else if (ModelUtils .isMapSchema (p )) {
618- Schema inner = ModelUtils .getAdditionalProperties (p );
635+ } else if (ModelUtils .isMapSchema (resolved )) {
636+ Schema inner = ModelUtils .getAdditionalProperties (resolved );
619637 if (inner == null ) {
620638 inner = new StringSchema ();
621639 }
622640 return "Table[string, " + getTypeDeclaration (inner ) + "]" ;
623641 }
624642
643+ // For non-containers, use the original schema to preserve model names
625644 String schemaType = getSchemaType (p );
626645 if (typeMapping .containsKey (schemaType )) {
627646 return typeMapping .get (schemaType );
@@ -719,10 +738,17 @@ private String sanitizeNimIdentifier(String name) {
719738
720739 @ Override
721740 public String toEnumVarName (String name , String datatype ) {
741+ // Handle negative numbers by prefixing with "Neg" to avoid collisions
742+ // e.g., -1 and 1 would both become `1` without this, causing invalid syntax
743+ if (name .startsWith ("-" )) {
744+ name = "Neg" + name .substring (1 );
745+ }
746+
722747 name = name .replace (" " , "_" );
723748 name = StringUtils .camelize (name );
724749
725- // starts with number or contains any character not allowed,see
750+ // starts with number or contains any character not allowed, see
751+ // https://nim-lang.org/docs/manual.html#lexical-analysis-identifiers-amp-keywords
726752 if (isValidIdentifier (name )) {
727753 return name ;
728754 } else {
0 commit comments