{"record":{"id":"31af039eb2e2fbc3","repo":"OpenAPITools/openapi-generator","slug":"unknown-casingtype","errorCode":null,"errorMessage":"Unknown CasingType","messagePattern":"Unknown CasingType","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java","lineNumber":185,"sourceCode":"     * @param allowRawIdentifiers Raw identifiers can't always be used, because of filename vs import mismatch.\n     * @return Sanitized string\n     */\n    public String sanitizeIdentifier(String name, CasingType casingType, String escapePrefix, String type, boolean allowRawIdentifiers) {\n        String originalName = name;\n\n        Function<String, String> casingFunction;\n        switch (casingType) {\n            case CAMEL_CASE:\n                // This probably seems odd, but it is necessary for two reasons\n                // Compatibility with rust-server, such that MyIDList => my_id_list => MyIdList\n                // Conversion from SCREAMING_SNAKE_CASE to ScreamingSnakeCase\n                casingFunction = (input) -> camelize(underscore(input));\n                break;\n            case SNAKE_CASE:\n                casingFunction = StringUtils::underscore;\n                break;\n            default:\n                throw new IllegalArgumentException(\"Unknown CasingType\");\n        }\n\n        // Replace hyphens and periods with underscores\n        name = name.replaceAll(\"[\\\\.\\\\-]\", \"_\");\n\n        // Apply special character escapes, e.g. \"@type\" => \"At_type\"\n        // Remove the trailing underscore if necessary\n        if (!Strings.isNullOrEmpty(name)) {\n            boolean endedWithUnderscore = name.endsWith(\"_\");\n            name = escape(name, specialCharReplacements, charactersToAllow, \"_\");\n            if (!endedWithUnderscore && name.endsWith(\"_\")) {\n                name = org.apache.commons.lang3.StringUtils.chop(name);\n            }\n        }\n\n        // Sanitize any other special characters that weren't replaced\n        name = sanitizeName(name);\n","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java#L167-L203","documentation":"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.","triggerScenarios":"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.","commonSituations":"Maintaining a fork that adds a casing mode for Rust generators; merging upstream into a fork that extended the enum; running custom snapshot builds.","solutions":["If your fork added a CasingType constant, add the matching case in sanitizeIdentifier's switch","On stock openapi-generator, capture the stack trace and open an issue — a reachable 'Unknown CasingType' means an enum/switch mismatch regression","Generate with a released version instead of an unmerged custom build to confirm the fork is the cause"],"exampleFix":"// before (fork added SCREAMING_SNAKE_CASE; switch has no case for it)\npublic enum CasingType {CAMEL_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE}\n\n// after\npublic enum CasingType {CAMEL_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE}\n// ...\nswitch (casingType) {\n    case CAMEL_CASE: // ...\n    case SNAKE_CASE: // ...\n    case SCREAMING_SNAKE_CASE:\n        casingFunction = (input) -> underscore(input).toUpperCase(Locale.ROOT);\n        break;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { generator.generate(); } catch (IllegalArgumentException e) { if (\"Unknown CasingType\".equals(e.getMessage())) { /* internal enum/switch mismatch: only reachable in custom forks */ } throw e; }","preventionTips":["When adding an enum constant in a fork, update every switch over it in the same commit","Add a unit test that drives sanitizeIdentifier with each enum constant","Run generator integration tests before shipping custom builds"],"tags":["rust","openapi-generator","internal","defensive-code"],"backgroundTag":"unsupported-enum-value","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}