OpenAPITools/openapi-generator · error · IllegalArgumentException

mapNumberTo value must be Union[StrictFloat, StrictInt], Str

Error message

mapNumberTo value must be Union[StrictFloat, StrictInt], StrictStr or float

What it means

AbstractPythonPydanticV1Codegen.setMapNumberTo accepts exactly three strings: 'Union[StrictFloat, StrictInt]', 'StrictFloat', 'float' (no Decimal — that value belongs to the non-v1 AbstractPythonCodegen set). Anything else throws this IllegalArgumentException. Beware the message text: it says 'StrictStr' but the code compares 'StrictFloat' — StrictStr is NOT actually accepted; the wording is a copy-paste bug in the message itself.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java:1606

                        exampleImports.add(cp.dataType);
                    }
                } else {
                    LOGGER.error("Failed to look up {} from the imports (map of set) of models.", cp.dataType);
                }
            }
            return cp.dataType;
        } else {
            throw new RuntimeException("Error! Codegen Property not yet supported in getPydanticType: " + cp);
        }
    }

    public void setMapNumberTo(String mapNumberTo) {
        if ("Union[StrictFloat, StrictInt]".equals(mapNumberTo)
                || "StrictFloat".equals(mapNumberTo)
                || "float".equals(mapNumberTo)) {
            this.mapNumberTo = mapNumberTo;
        } else {
            throw new IllegalArgumentException("mapNumberTo value must be Union[StrictFloat, StrictInt], StrictStr or float");
        }
    }

    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
        name = name.substring(1, name.length() - 1);

        if (name.length() == 0) {
            return "EMPTY";
        }

        if (" ".equals(name)) {

View on GitHub (pinned to fcec517be3)

Solutions

  1. Use one of the exactly accepted values: float, StrictFloat, or Union[StrictFloat, StrictInt]
  2. Do not use StrictStr here despite the message naming it — the comparison in the source is StrictFloat
  3. If you need Decimal, generate with -g python instead, whose SUPPORTED_NUMBER_MAPPINGS includes it

Example fix

# before
java -jar openapi-generator-cli.jar generate -g python-pydantic-v1 -i api.yaml -p mapNumberTo=StrictStr

# after
java -jar openapi-generator-cli.jar generate -g python-pydantic-v1 -i api.yaml -p mapNumberTo=StrictFloat
Defensive patterns

Strategy: validation

Validate before calling

// Java: allowed values for the pydantic-v1 generator (no StrictStr, no Decimal)
Set<String> allowed = Set.of("Union[StrictFloat, StrictInt]", "StrictFloat", "float");
String v = (String) config.additionalProperties().get("mapNumberTo");
if (v != null && !allowed.contains(v)) {
    throw new IllegalArgumentException("mapNumberTo must be one of " + allowed);
}

Try / catch

try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("mapNumberTo value must be")) { /* pick float/StrictFloat/Union[...]; ignore the misleading StrictStr in the text */ } throw e; }

Prevention

When it happens

Trigger: -p mapNumberTo=StrictStr (suggested by the error text but rejected on retry), mapNumberTo=Decimal (valid for -g python, invalid for the pydantic-v1 generator), or any casing/whitespace deviation from the three exact strings, when generating with -g python-pydantic-v1.

Common situations: Cross-generator copy-paste of option values between python and python-pydantic-v1 configs; developers following the misleading error message and retrying with StrictStr.

Related errors


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/25a9c5d13e80cae7. Report an issue: GitHub.