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

AbstractKotlinCodegen.setEnumPropertyNaming parses the enumPropertyNaming option into the Kotlin-specific KotlinEnumNamingType enum instead of the shared CodegenConstants enum. Values include camelCase, PascalCase, snake_case, original, UPPERCASE plus Kotlin-only variants (a backtick-escaped original mode); anything else throws RuntimeException with the full valid list appended.

Source

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

    public String escapeUnsafeCharacters(String input) {
        return input.replace("*/", "*_/").replace("/*", "/_*");
    }


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

    @Override
    public String toExampleValue(Schema schema) {
        if (schema.getExample() != null) {
            return super.toExampleValue(schema);
        }
        return null;
    }

    /**
     * returns the OpenAPI type for the property
     *
     * @param p OpenAPI property object
     * @return string presentation of the type
     **/
    @Override

View on GitHub (pinned to fcec517be3)

Solutions

  1. Use one of the values listed in the error message — e.g. camelCase, PascalCase, snake_case, original, UPPERCASE (plus Kotlin-specific backtick variants).
  2. Do not reuse Java's MACRO_CASE/legacy values with Kotlin generators; keep per-language option sets.
  3. Verify casing exactly — the match is case-sensitive valueOf lookup.

Example fix

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

Strategy: type-guard

Validate before calling

// Validate before passing the option to a Kotlin generator
if (!isKotlinEnumPropertyNaming(opts.enumPropertyNaming)) {
    throw new Error('Kotlin enumPropertyNaming must be one of camelCase, PascalCase, snake_case, original, UPPERCASE (or Kotlin backtick variants)');
}

Type guard

const KOTLIN_ENUM_PROPERTY_NAMING = ['camelCase', 'PascalCase', 'snake_case', 'original', 'UPPERCASE'] as const;
export type KotlinEnumPropertyNaming = typeof KOTLIN_ENUM_PROPERTY_NAMING[number];
export function isKotlinEnumPropertyNaming(v: string): v is KotlinEnumPropertyNaming {
    return (KOTLIN_ENUM_PROPERTY_NAMING as readonly string[]).includes(v);
}

Prevention

When it happens

Trigger: Passing -p enumPropertyNaming=macro_case or another non-Kotlin value to a Kotlin generator (kotlin, kotlin-spring). KotlinEnumNamingType.valueOf throws IllegalArgumentException and the wrapper RuntimeException aborts.

Common situations: Copying a Java generator's enumPropertyNaming value (MACRO_CASE/legacy) into a Kotlin build; casing or hyphenation slips; assuming the shared CodegenConstants list applies.

Related errors


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