{"record":{"id":"01e959abf274630f","repo":"OpenAPITools/openapi-generator","slug":"s-file-suffix-only-allows-and-alphanumer-01e959","errorCode":null,"errorMessage":"%s file suffix only allows '.', '-' and alphanumeric characters.","messagePattern":"(.+?) file suffix only allows '\\.', '-' and alphanumeric characters\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java","lineNumber":507,"sourceCode":"            result = result.substring(prefix.length());\n        }\n        if (suffix.length() > 0 && result.endsWith(suffix)) {\n            result = result.substring(0, result.length() - suffix.length());\n        }\n\n        return result;\n    }\n\n    /**\n     * Validates that the given string value only contains '-', '.' and alpha numeric characters.\n     * Throws an IllegalArgumentException, if the string contains any other characters.\n     *\n     * @param argument The name of the argument being validated. This is only used for displaying an error message.\n     * @param value    The value that is being validated.\n     */\n    private void validateFileSuffixArgument(String argument, String value) {\n        if (!value.matches(FILE_NAME_SUFFIX_PATTERN)) {\n            throw new IllegalArgumentException(\n                    String.format(Locale.ROOT, \"%s file suffix only allows '.', '-' and alphanumeric characters.\", argument)\n            );\n        }\n    }\n\n    /**\n     * Validates that the given string value only contains alpha numeric characters.\n     * Throws an IllegalArgumentException, if the string contains any other characters.\n     *\n     * @param argument The name of the argument being validated. This is only used for displaying an error message.\n     * @param value    The value that is being validated.\n     */\n    private void validateClassSuffixArgument(String argument, String value) {\n        if (!value.matches(CLASS_NAME_SUFFIX_PATTERN)) {\n            throw new IllegalArgumentException(\n                    String.format(Locale.ROOT, \"%s class suffix only allows alphanumeric characters.\", argument)\n            );\n        }","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNestjsClientCodegen.java#L489-L525","documentation":"The typescript-nestjs client generator validates the file-name suffix options 'serviceFileSuffix' and 'modelFileSuffix' against the regex ^[a-zA-Z0-9.-]*$ (TypeScriptNestjsClientCodegen.java:48, validated at lines 191/199). When a suffix contains any other character (underscore, space, slash, '$'), generation aborts with this IllegalArgumentException, where %s is 'Service' or 'Model'. It is a fail-fast guard: the suffix is concatenated into emitted file names, so an illegal character would produce invalid or unsafe paths.","triggerScenarios":"Running the generator with -DserviceFileSuffix=_service or -DmodelFileSuffix=_model (underscore is the classic offender), or programmatically via additionalProperties.put(\"serviceFileSuffix\", \" my api\"). Any value matching [^a-zA-Z0-9.-] triggers it during processOpts.","commonSituations":"Teams migrating from typescript-angular or NestJS conventions that use snake_case file names (user_service.service.ts); copying suffix values from other generators that allow underscores; YAML/JSON config files where a trailing space or quote slips into the suffix string.","solutions":["Change the suffix to use only letters, digits, '.' and '-' (e.g. replace '_service' with '.service' or '-service').","Check both option keys in your command/config: serviceFileSuffix and modelFileSuffix — the %s in the message tells you which one ('Service' or 'Model') is invalid.","If you truly need underscores in generated file names, post-process the output with a rename script after generation instead of passing them to the generator."],"exampleFix":"# before\nopenapi-generator-cli generate -g typescript-nestjs \\\n  -DserviceFileSuffix=_service.ts\n\n# after\nopenapi-generator-cli generate -g typescript-nestjs \\\n  -DserviceFileSuffix=.service.ts","handlingStrategy":"validation","validationCode":"# in CI before generation\nif ! printf '%s' \"$SERVICE_FILE_SUFFIX$MODEL_FILE_SUFFIX\" | grep -Eq '^[a-zA-Z0-9.-]*$'; then\n  echo \"ERROR: file suffixes may only contain '.', '-' and alphanumerics\" >&2\n  exit 1\nfi","typeGuard":"// TypeScript (build script validating options)\nconst isValidFileSuffix = (v: string | undefined): boolean =>\n  v === undefined || /^[a-zA-Z0-9.-]*$/.test(v);","tryCatchPattern":"try {\n    org.openapitools.codegen.DefaultGenerator generator = new org.openapitools.codegen.DefaultGenerator();\n    generator.opts(clientOptInput).generate();\n} catch (IllegalArgumentException e) {\n    // fail the build with the offending option instead of a stack dump\n    throw new RuntimeException(\"Invalid typescript-nestjs suffix option: \" + e.getMessage(), e);\n}","preventionTips":["Keep a single naming-convention constant (e.g. '.service') in your build config and reuse it for file suffixes instead of free-text values.","Add a lint step in CI that regex-checks every -D*Suffix value before invoking openapi-generator.","Remember the two regexes: file suffixes allow '.', '-'; class suffixes allow neither."],"tags":["typescript","nestjs","codegen","config-validation","file-naming"],"backgroundTag":"invalid-option-value","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}