OpenAPITools/openapi-generator · error · RuntimeException

%s is an invalid enum property naming option. Please choose

Error message

%s is an invalid enum property naming option. Please choose from:

What it means

AbstractJavaCodegen.setEnumPropertyNaming parses the enumPropertyNaming option into the generator-local ENUM_PROPERTY_NAMING_TYPE enum, which for the Java generators is MACRO_CASE, legacy, original — not the cross-language set used by C# or Kotlin. An unrecognized string throws RuntimeException with the valid names appended.

Source

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

    @Override
    public boolean isTypeErasedGenerics() {
        return true;
    }

    /**
     * Sets the naming convention for Java enum properties
     *
     * @param enumPropertyNamingType The string representation of the naming convention, as defined by {@link ENUM_PROPERTY_NAMING_TYPE}
     */
    public void setEnumPropertyNaming(final String enumPropertyNamingType) {
        try {
            this.enumPropertyNaming = ENUM_PROPERTY_NAMING_TYPE.valueOf(enumPropertyNamingType);
        } catch (IllegalArgumentException ex) {
            StringBuilder sb = new StringBuilder(enumPropertyNamingType + " is an invalid enum property naming option. Please choose from:");
            for (ENUM_PROPERTY_NAMING_TYPE t : ENUM_PROPERTY_NAMING_TYPE.values()) {
                sb.append("\n  ").append(t.name());
            }
            throw new RuntimeException(sb.toString());
        }
    }

    @Override
    protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
        this.jSpecifyNullableLambda = new JSpecifyNullableLambda();
        // Add jSpecify nullable annotation in the correct location before or inside a declaration
        // use cases:
        //
        // private {{#lambda.jSpecifyDatatype}}{{{dataType}}}{{/lambda.jSpecifyDatatype}} {{param}}
        // ->
        // private @Nullable Time param
        // private java.time.@Nullable Time
        // private Time param
        //
        // {{#lambda.jSpecifyDatatype}}{{{dataType}}}{{/lambda.jSpecifyDatatype}} {{param}}
        // ->
        // @Nullable Time param

View on GitHub (pinned to fcec517be3)

Solutions

  1. For Java generators use exactly one of MACRO_CASE, legacy, original.
  2. Split per-language option sets instead of one shared -p block when different generators accept different naming values.
  3. Fix casing: MACRO_CASE is uppercase with underscores, legacy is lowercase.

Example fix

# before:
openapi-generator-cli generate -g java -i api.yaml -p enumPropertyNaming=camelCase
# after:
openapi-generator-cli generate -g java -i api.yaml -p enumPropertyNaming=MACRO_CASE
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate before passing the option to a Java generator
if (!isJavaEnumPropertyNaming(opts.enumPropertyNaming)) {
    throw new Error('Java enumPropertyNaming must be one of MACRO_CASE, legacy, original');
}

Type guard

const JAVA_ENUM_PROPERTY_NAMING = ['MACRO_CASE', 'legacy', 'original'] as const;
export type JavaEnumPropertyNaming = typeof JAVA_ENUM_PROPERTY_NAMING[number];
export function isJavaEnumPropertyNaming(v: string): v is JavaEnumPropertyNaming {
    return (JAVA_ENUM_PROPERTY_NAMING as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Passing -p enumPropertyNaming=camelCase (valid for C#/Kotlin but not Java), snake_case, or a case-mismatched 'macro_case' to a Java generator. valueOf throws IllegalArgumentException and the wrapper RuntimeException aborts option processing.

Common situations: Sharing one options file across generators of different languages; assuming the enumPropertyNaming values are universal across openapi-generator; casing slips like macro_case.

Related errors


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