OpenAPITools/openapi-generator · error · IllegalArgumentException

Unknown CasingType

Error message

Unknown CasingType

What it means

AbstractRustCodegen.sanitizeIdentifier picks a casing function by switching over the CasingType enum: CAMEL_CASE uses camelize(underscore(x)) and SNAKE_CASE uses underscore; the default branch throws IllegalArgumentException('Unknown CasingType'). The enum (line 152) declares only those two constants and both are handled, so in stock builds this branch is defensive dead code — it exists to catch forks or PRs that add a CasingType constant without updating the switch.

Source

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

     * @param allowRawIdentifiers Raw identifiers can't always be used, because of filename vs import mismatch.
     * @return Sanitized string
     */
    public String sanitizeIdentifier(String name, CasingType casingType, String escapePrefix, String type, boolean allowRawIdentifiers) {
        String originalName = name;

        Function<String, String> casingFunction;
        switch (casingType) {
            case CAMEL_CASE:
                // This probably seems odd, but it is necessary for two reasons
                // Compatibility with rust-server, such that MyIDList => my_id_list => MyIdList
                // Conversion from SCREAMING_SNAKE_CASE to ScreamingSnakeCase
                casingFunction = (input) -> camelize(underscore(input));
                break;
            case SNAKE_CASE:
                casingFunction = StringUtils::underscore;
                break;
            default:
                throw new IllegalArgumentException("Unknown CasingType");
        }

        // Replace hyphens and periods with underscores
        name = name.replaceAll("[\\.\\-]", "_");

        // Apply special character escapes, e.g. "@type" => "At_type"
        // Remove the trailing underscore if necessary
        if (!Strings.isNullOrEmpty(name)) {
            boolean endedWithUnderscore = name.endsWith("_");
            name = escape(name, specialCharReplacements, charactersToAllow, "_");
            if (!endedWithUnderscore && name.endsWith("_")) {
                name = org.apache.commons.lang3.StringUtils.chop(name);
            }
        }

        // Sanitize any other special characters that weren't replaced
        name = sanitizeName(name);

View on GitHub (pinned to fcec517be3)

Solutions

  1. If your fork added a CasingType constant, add the matching case in sanitizeIdentifier's switch
  2. On stock openapi-generator, capture the stack trace and open an issue — a reachable 'Unknown CasingType' means an enum/switch mismatch regression
  3. Generate with a released version instead of an unmerged custom build to confirm the fork is the cause

Example fix

// before (fork added SCREAMING_SNAKE_CASE; switch has no case for it)
public enum CasingType {CAMEL_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE}

// after
public enum CasingType {CAMEL_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE}
// ...
switch (casingType) {
    case CAMEL_CASE: // ...
    case SNAKE_CASE: // ...
    case SCREAMING_SNAKE_CASE:
        casingFunction = (input) -> underscore(input).toUpperCase(Locale.ROOT);
        break;
Defensive patterns

Strategy: try-catch

Try / catch

try { generator.generate(); } catch (IllegalArgumentException e) { if ("Unknown CasingType".equals(e.getMessage())) { /* internal enum/switch mismatch: only reachable in custom forks */ } throw e; }

Prevention

When it happens

Trigger: Not reachable through user options in the shipped generator. It fires only when someone extends enum CasingType with a new constant (e.g. SCREAMING_SNAKE_CASE) but leaves this switch unchanged, then generates — typically in a local fork or unmerged feature branch.

Common situations: Maintaining a fork that adds a casing mode for Rust generators; merging upstream into a fork that extended the enum; running custom snapshot builds.

Related errors


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