{"record":{"id":"151d1aef35cbcd3c","repo":"OpenAPITools/openapi-generator","slug":"number-is-too-large-to-fit-into-i128","errorCode":null,"errorMessage":"Number is too large to fit into i128","messagePattern":"Number is too large to fit into i128","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java","lineNumber":132,"sourceCode":"                return \"u64\";\n            } else if (requiredBits <= 128) {\n                return \"u128\";\n            }\n        } else {\n            if (requiredBits <= 7 && knownRange) {\n                return \"i8\";\n            } else if (requiredBits <= 15 && knownRange) {\n                return \"i16\";\n            } else if (requiredBits <= 31) {\n                return \"i32\";\n            } else if (requiredBits <= 63) {\n                return \"i64\";\n            } else if (requiredBits <= 127) {\n                return \"i128\";\n            }\n        }\n\n        throw new RuntimeException(\"Number is too large to fit into i128\");\n    }\n\n    /**\n     * Determine if an integer property can be guaranteed to fit into an unsigned data type.\n     *\n     * @param minimum          The minimum value as set in the specification.\n     * @param exclusiveMinimum If boundary values are excluded by the specification.\n     * @return True if the effective minimum is greater than or equal to zero.\n     */\n    @VisibleForTesting\n    public boolean canFitIntoUnsigned(@Nullable BigInteger minimum, boolean exclusiveMinimum) {\n        return Optional.ofNullable(minimum).map(min -> {\n            if (exclusiveMinimum) {\n                min = min.add(BigInteger.ONE);\n            }\n            return min.signum() >= 0;\n        }).orElse(false);\n    }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java#L114-L150","documentation":"AbstractRustCodegen maps integer schema bounds to Rust integer types: it adjusts exclusive bounds, computes requiredBits = max(bitLength(minimum), bitLength(maximum)), then picks u8..u128 / i8..i128. When requiredBits exceeds the largest type (127 magnitude bits signed, 128 unsigned) no branch matches and it throws RuntimeException('Number is too large to fit into i128') — the spec's declared numeric range is wider than any native Rust integer.","triggerScenarios":"An integer schema with minimum/maximum (or exclusiveMinimum/exclusiveMaximum) outside the 128-bit range when generating any Rust client/server, e.g. maximum: 1.0e+40, maximum: 9999999999999999999999999999999999999999, or minimum beyond -2^127. BigInteger.bitLength counts magnitude bits, so anything past ~1.7e38 overflows.","commonSituations":"Specs using a huge maximum as an 'effectively unbounded' sentinel; JSON Schemas generated from systems with arbitrary-precision integers; test fixtures with extreme magnitudes.","solutions":["Tighten minimum/maximum to values that fit native integers — realistically i64 bounds such as maximum: 9223372036854775807","Remove meaningless min/max constraints entirely; with no bounds the generator picks a default integer type","If values genuinely exceed 128 bits, model the field as type: string (or wire up a bignum crate via templates) instead of integer"],"exampleFix":"# before\nmaximum: 1.0e+40\n\n# after\nmaximum: 9223372036854775807","handlingStrategy":"validation","validationCode":"// JS: reject integer bounds beyond 128-bit before Rust generation\nconst LIMIT = 2n ** 127n; // signed headroom used by the codegen\nfunction bitLen(v) { return (v < 0n ? -v : v).toString(2).length; }\nfor (const s of collectSchemas(spec)) {\n  if (s.type !== 'integer') continue;\n  for (const [k, v] of Object.entries(s)) {\n    if ((k === 'minimum' || k === 'maximum') && bitLen(BigInt(v)) > 127) fail(`${s.title}: ${k} exceeds i128`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { generator.generate(); } catch (RuntimeException e) { if (\"Number is too large to fit into i128\".equals(e.getMessage())) { /* tighten or drop the huge minimum/maximum */ } throw e; }","preventionTips":["Use realistic 64-bit bounds in specs, not huge sentinel values","Drop min/max when they carry no real constraint","Model truly unbounded/big numbers as strings or bignum types"],"tags":["rust","numeric","openapi-spec","validation"],"backgroundTag":"integer-overflow","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}