OpenAPITools/openapi-generator · error · IllegalArgumentException

Invalid model property naming '{name}'. Must be 'original',

Error message

Invalid model property naming '{name}'. Must be 'original', 'camelCase', 'PascalCase' or 'snake_case'

What it means

AbstractScalaCodegen.getNameUsingModelPropertyNaming switches over MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming()) and covers all four constants (original, camelCase, PascalCase, snake_case). The default branch's IllegalArgumentException is therefore defensive dead code: reachable only if the enum gains a constant without a matching case here. Its message also interpolates the property name, not the invalid naming value, so it reads misleadingly.

Source

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

        if (isReservedWord(varName) || varName.matches("^\\d.*")) {
            varName = escapeReservedWord(varName);
        }

        return varName;
    }

    public String getNameUsingModelPropertyNaming(String name) {
        switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
            case original:
                return name;
            case camelCase:
                return camelize(name, LOWERCASE_FIRST_LETTER);
            case PascalCase:
                return camelize(name);
            case snake_case:
                return underscore(name);
            default:
                throw new IllegalArgumentException("Invalid model property naming '" +
                        name + "'. Must be 'original', 'camelCase', " +
                        "'PascalCase' or 'snake_case'");
        }
    }

    @Override
    public String escapeReservedWord(String name) {
        if (this.reservedWordsMappings().containsKey(name)) {
            return this.reservedWordsMappings().get(name);
        }
        // Reserved words will be further escaped at the mustache compiler level.
        // Scala escaping done here (via `, without compiler escaping) would otherwise be HTML encoded.
        return "`" + name + "`";
    }

    @Override
    public Mustache.Compiler processCompiler(Mustache.Compiler compiler) {
        Mustache.Escaper SCALA = new Mustache.Escaper() {

View on GitHub (pinned to fcec517be3)

Solutions

  1. If your fork added a naming enum member, add the corresponding case in getNameUsingModelPropertyNaming in the same change
  2. On stock builds, file an issue with the stack trace — reaching this branch signals an enum/switch mismatch regression
  3. Add a unit test that iterates all enum constants through this method so the mismatch fails at build time, not at generation time

Example fix

// before (fork added KEBAB_CASE constant; switch lacks a case)
// after
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
    case original: return name;
    case camelCase: return camelize(name, LOWERCASE_FIRST_LETTER);
    case PascalCase: return camelize(name);
    case snake_case: return underscore(name);
    case KEBAB_CASE: return name.replace('_', '-'); // new case added with the enum member
    default: throw new IllegalArgumentException("Invalid model property naming");
}
Defensive patterns

Strategy: try-catch

Try / catch

try { generator.generate(); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Invalid model property naming")) { /* stock builds cannot reach this branch: report enum/switch mismatch */ } throw e; }

Prevention

When it happens

Trigger: Not user-triggerable in stock builds — setModelPropertyNaming already constrains modelPropertyNaming to valid enum names, and every current name has a case. It fires only in forks that add a MODEL_PROPERTY_NAMING_TYPE member without extending this switch.

Common situations: Custom forks adding a naming style (e.g. SCREAMING_SNAKE_CASE); nothing in normal CLI/Maven/Gradle use can produce it.

Related errors


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