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

Defensive default arm inside getNameUsingModelPropertyNaming, which rewrites each model property name according to the configured convention for the javascript-apollo generator. The switch is over the MODEL_PROPERTY_NAMING_TYPE enum whose constants are exactly original, camelCase, PascalCase, snake_case — so the default arm is unreachable: an invalid string fails earlier, either in setModelPropertyNaming (which rejects unknown values) or at valueOf() itself. The message also prints the property name being converted rather than the invalid convention, which is misleading.

Source

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

    }

    @Override
    public String toModelTestFilename(String name) {
        return toModelName(name) + ".spec";
    }

    private 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 toVarName(String name) {
        // sanitize name
        name = sanitizeName(name);  // FIXME parameter should not be assigned. Also declare it as "final"

        if ("_".equals(name)) {
            name = "_u";
        }

        // if it's all upper case, do nothing
        if (name.matches("^[A-Z_]*$")) {
            return name;
        }

View on GitHub (pinned to fcec517be3)

Solutions

  1. Treat this text as a modelPropertyNaming problem: check the option value first — the setter at JavascriptApolloClientCodegen.java:609 is the realistic source.
  2. Use one of original, camelCase, PascalCase, snake_case with exact casing.
  3. If you subclass this generator, set the convention via setModelPropertyNaming, never by direct field assignment.

Example fix

# before
openapi-generator-cli generate -g javascript-apollo -i api.yaml -p modelPropertyNaming=snake
# after
openapi-generator-cli generate -g javascript-apollo -i api.yaml -p modelPropertyNaming=snake_case
Defensive patterns

Strategy: validation

Validate before calling

# validate at the option level — this line is a defensive arm, the setter is the real gate
mpn="${MODEL_PROPERTY_NAMING:-camelCase}"
case "$mpn" in
  original|camelCase|PascalCase|snake_case) ;;
  *) echo "modelPropertyNaming must be original|camelCase|PascalCase|snake_case, got: $mpn" >&2; exit 2 ;;
esac

Type guard

private static final java.util.Set<String> NAMING_CONVENTIONS =
        java.util.Set.of("original", "camelCase", "PascalCase", "snake_case");

boolean isValidNamingConvention(String v) {
    return v != null && NAMING_CONVENTIONS.contains(v);
}

Try / catch

try {
    new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
    failBuild("javascript-apollo naming config rejected: " + e.getMessage());
}

Prevention

When it happens

Trigger: Not reachable through supported inputs: `-p modelPropertyNaming=<bad>` is rejected by setModelPropertyNaming (JavascriptApolloClientCodegen.java:609) before this line runs. Only a subclass that assigns the modelPropertyNaming field directly to a non-enum string, or a future enum constant added without a matching case, could hit it.

Common situations: Rarely seen; developers who search this message almost always actually hit the identically-worded setter error caused by a misspelled modelPropertyNaming value.

Related errors


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