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

AbstractCSharpCodegen.setEnumPropertyNaming parses the enumPropertyNaming option into CodegenConstants.ENUM_PROPERTY_NAMING_TYPE. A string that is not one of the enum constants throws this RuntimeException, with the message appending the full list of valid values.

Source

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

    }

    public void setUseSourceGeneration(final Boolean useSourceGeneration) {
        this.useSourceGeneration = useSourceGeneration;
    }

    public boolean getUseSourceGeneration() {
        return this.useSourceGeneration;
    }

    public void setEnumPropertyNaming(final String enumPropertyNamingType) {
        try {
            this.enumPropertyNaming = CodegenConstants.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 (CodegenConstants.ENUM_PROPERTY_NAMING_TYPE t : CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.values()) {
                sb.append("\n  ").append(t.name());
            }
            throw new RuntimeException(sb.toString());
        }
    }

    @Override
    public String toEnumValue(String value, String datatype) {
        // C# only supports enums as literals for int, int?, long, long?, byte, and byte?. All else must be treated as strings.
        // Per: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/enum
        // The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong.
        // but we're not supporting unsigned integral types or shorts.
        if (datatype.startsWith("int") || datatype.startsWith("uint") ||
                datatype.startsWith("long") || datatype.startsWith("ulong") ||
                datatype.startsWith("byte")) {
            return value;
        }

        final String partiallyEscaped = value
                .replace("\n", "\\n")
                .replace("\t", "\\t")

View on GitHub (pinned to fcec517be3)

Solutions

  1. Use exactly one of the values printed in the error message (camelCase, PascalCase, snake_case, original, UPPERCASE) — matching case.
  2. Check for spelling/casing slips such as camelcase, pascalCase, or snake-case.
  3. When moving configs between generator versions or languages, re-check that generator's supported naming options.

Example fix

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

Strategy: type-guard

Validate before calling

// Validate before passing the option
if (!isCSharpEnumNaming(opts.enumPropertyNaming)) {
    throw new Error('enumPropertyNaming must be one of camelCase, PascalCase, snake_case, original, UPPERCASE');
}

Type guard

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

Prevention

When it happens

Trigger: Passing -p enumPropertyNaming=camelcase (wrong case) or a nonexistent value like upper_snake with a C# generator (csharp, csharp-netcore). The value is matched case-sensitively against the constants camelCase, PascalCase, snake_case, original, UPPERCASE.

Common situations: Typos and wrong casing in generator config; copying an enumPropertyNaming value that only exists in a different generator family (e.g. a Kotlin-only or Java-only value); options carried over from an older release whose value set differed.

Related errors


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