OpenAPITools/openapi-generator · error · RuntimeException
Number is too large to fit into i128
Error message
Number is too large to fit into i128
What it means
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.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java:132
return "u64";
} else if (requiredBits <= 128) {
return "u128";
}
} else {
if (requiredBits <= 7 && knownRange) {
return "i8";
} else if (requiredBits <= 15 && knownRange) {
return "i16";
} else if (requiredBits <= 31) {
return "i32";
} else if (requiredBits <= 63) {
return "i64";
} else if (requiredBits <= 127) {
return "i128";
}
}
throw new RuntimeException("Number is too large to fit into i128");
}
/**
* Determine if an integer property can be guaranteed to fit into an unsigned data type.
*
* @param minimum The minimum value as set in the specification.
* @param exclusiveMinimum If boundary values are excluded by the specification.
* @return True if the effective minimum is greater than or equal to zero.
*/
@VisibleForTesting
public boolean canFitIntoUnsigned(@Nullable BigInteger minimum, boolean exclusiveMinimum) {
return Optional.ofNullable(minimum).map(min -> {
if (exclusiveMinimum) {
min = min.add(BigInteger.ONE);
}
return min.signum() >= 0;
}).orElse(false);
}View on GitHub (pinned to fcec517be3)
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
Example fix
# before maximum: 1.0e+40 # after maximum: 9223372036854775807
Defensive patterns
Strategy: validation
Validate before calling
// JS: reject integer bounds beyond 128-bit before Rust generation
const LIMIT = 2n ** 127n; // signed headroom used by the codegen
function bitLen(v) { return (v < 0n ? -v : v).toString(2).length; }
for (const s of collectSchemas(spec)) {
if (s.type !== 'integer') continue;
for (const [k, v] of Object.entries(s)) {
if ((k === 'minimum' || k === 'maximum') && bitLen(BigInt(v)) > 127) fail(`${s.title}: ${k} exceeds i128`);
}
} Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Specs using a huge maximum as an 'effectively unbounded' sentinel; JSON Schemas generated from systems with arbitrary-precision integers; test fixtures with extreme magnitudes.
Related errors
- Cannot merge specs where some declare an OpenAPI version and
- Pattern must follow the Perl /pattern/modifiers convention.
- Error! Failed to process getPydanticType when getting the co
- Error! Codegen Parameter not yet supported in getPydanticTyp
- Please report the issue as the parameter name cannot be null
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/151d1aef35cbcd3c.
Report an issue: GitHub.