OpenAPITools/openapi-generator · error · IllegalArgumentException
mapNumberTo supports %s
Error message
mapNumberTo supports %s
What it means
Thrown by setMapNumberTo in AbstractPythonCodegen, the base for the modern Python generators (python, python-fastapi, etc.). The mapNumberTo option selects which Python type OpenAPI 'number' properties map to, and only the strings in SUPPORTED_NUMBER_MAPPINGS are accepted: 'Union[StrictFloat, StrictInt]', 'StrictFloat', 'float', 'Decimal'. Any other string fails with this IllegalArgumentException; the message interpolates the exact allowed set.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java:1241
PythonImports moduleImports,
String classname) {
PydanticType pt = new PydanticType(
modelImports,
exampleImports,
postponedModelImports,
postponedExampleImports,
moduleImports,
classname
);
return pt.getType(cp);
}
public void setMapNumberTo(String mapNumberTo) {
if (SUPPORTED_NUMBER_MAPPINGS.contains(mapNumberTo)) {
this.mapNumberTo = mapNumberTo;
} else {
throw new IllegalArgumentException(String.format(Locale.ROOT, "mapNumberTo supports %s", SUPPORTED_NUMBER_MAPPINGS));
}
}
public String toEnumVariableName(String name, String datatype) {
name = name.replace(".", "_DOT_");
if ("int".equals(datatype)) {
return "NUMBER_" + name.replace("-", "MINUS_");
}
// remove quote e.g. 'abc' => abc
if (name.startsWith("'") && name.endsWith("'")) {
name = name.substring(1, name.length() - 1);
}
if (name.length() == 0) {
return "EMPTY";
}View on GitHub (pinned to fcec517be3)
Solutions
- Re-run with an exact allowed value: -p mapNumberTo=float (the default), StrictFloat, Decimal, or Union[StrictFloat, StrictInt]
- Remove the option entirely and accept the generator default while you verify the spelling
- If you need pydantic strict types such as StrictStr, switch to the pydantic-v1 based generator (e.g. -g python-pydantic-v1) where that value is accepted
- Check for case sensitivity, exact brackets and commas — the check is an exact Set.contains string comparison
Example fix
# before java -jar openapi-generator-cli.jar generate -g python -i api.yaml -p mapNumberTo=StrictStr # after java -jar openapi-generator-cli.jar generate -g python -i api.yaml -p mapNumberTo=Union[StrictFloat, StrictInt]
Defensive patterns
Strategy: validation
Validate before calling
// Java (before calling the generator)
Set<String> allowed = Set.of("Union[StrictFloat, StrictInt]", "StrictFloat", "float", "Decimal");
String v = (String) config.additionalProperties().get("mapNumberTo");
if (v != null && !allowed.contains(v)) {
throw new IllegalArgumentException("mapNumberTo must be one of " + allowed + ", got: " + v);
} Try / catch
try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("mapNumberTo supports")) { /* config error: fix the option value, do not retry */ } throw e; } Prevention
- Keep generator options in a checked-in config (-c config.json) instead of ad-hoc CLI flags
- Validate -p key=value pairs against the generator's documented option list in a pre-build step
- Remember the accepted set differs between -g python and -g python-pydantic-v1
When it happens
Trigger: Running a Python-family generator with -p mapNumberTo=<value> (or additionalProperties in the Maven/Gradle plugin) where <value> is not byte-for-byte one of the four allowed strings: mapNumberTo=StrictStr, mapNumberTo=decimal (lowercase), mapNumberTo=Decimal on an old release before Decimal was added, or 'Union[StrictFloat, StrictInt]' with stray whitespace or smart quotes.
Common situations: Copying mapNumberTo=StrictStr from pydantic-v1 generator examples (valid there, rejected by this codegen); case/bracket typos in the Union value; upgrading or downgrading generator versions where the accepted set differed.
Related errors
- mapNumberTo value must be Union[StrictFloat, StrictInt], Str
- recursionLimit must be an integer, e.g. 2000.
- recursionLimit must be an integer, e.g. 2000.
- Error! Codegen Property not yet supported in getPydanticType
- Error! Codegen Property not yet supported in getPydanticType
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/1d00687c49cba42b.
Report an issue: GitHub.