OpenAPITools/openapi-generator · error · IllegalArgumentException

%s class suffix only allows alphanumeric characters.

Error message

%s class suffix only allows alphanumeric characters.

What it means

The typescript-nestjs client generator validates the class-name suffix options 'serviceSuffix' and 'modelSuffix' against ^[a-zA-Z0-9]*$ (TypeScriptNestjsClientCodegen.java:47, validated at lines 187/195). Unlike file suffixes, dots and dashes are forbidden because the value is appended to TypeScript class/identifier names, where '.' and '-' would be syntax errors. %s in the message is 'Service' or 'Model'.

Source

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

     */
    private void validateFileSuffixArgument(String argument, String value) {
        if (!value.matches(FILE_NAME_SUFFIX_PATTERN)) {
            throw new IllegalArgumentException(
                    String.format(Locale.ROOT, "%s file suffix only allows '.', '-' and alphanumeric characters.", argument)
            );
        }
    }

    /**
     * Validates that the given string value only contains alpha numeric characters.
     * Throws an IllegalArgumentException, if the string contains any other characters.
     *
     * @param argument The name of the argument being validated. This is only used for displaying an error message.
     * @param value    The value that is being validated.
     */
    private void validateClassSuffixArgument(String argument, String value) {
        if (!value.matches(CLASS_NAME_SUFFIX_PATTERN)) {
            throw new IllegalArgumentException(
                    String.format(Locale.ROOT, "%s class suffix only allows alphanumeric characters.", argument)
            );
        }
    }

    /**
     * Set the file naming type.
     *
     * @param fileNaming the file naming to use
     */
    private void setFileNaming(String fileNaming) {
        if ("camelCase".equals(fileNaming) || "kebab-case".equals(fileNaming)) {
            this.fileNaming = fileNaming;
        } else {
            throw new IllegalArgumentException("Invalid file naming '" +
                    fileNaming + "'. Must be 'camelCase' or 'kebab-case'");
        }
    }

View on GitHub (pinned to fcec517be3)

Solutions

  1. Strip '.', '-' and '_' from the class suffix — use pure alphanumerics (e.g. 'Service', 'Model', 'GenModel').
  2. Use separate values: dotted/kebab suffixes belong in serviceFileSuffix/modelFileSuffix only; keep serviceSuffix/modelSuffix alphanumeric.
  3. Re-run generation; the message's %s ('Service' or 'Model') identifies the offending option.

Example fix

# before
openapi-generator-cli generate -g typescript-nestjs \
  -DmodelSuffix=.Model

# after
openapi-generator-cli generate -g typescript-nestjs \
  -DmodelSuffix=Model
Defensive patterns

Strategy: validation

Validate before calling

if ! printf '%s' "$SERVICE_SUFFIX$MODEL_SUFFIX" | grep -Eq '^[a-zA-Z0-9]*$'; then
  echo "ERROR: class suffixes must be purely alphanumeric" >&2
  exit 1
fi

Type guard

const isValidClassSuffix = (v: string | undefined): boolean =>
  v === undefined || /^[a-zA-Z0-9]*$/.test(v);

Try / catch

catch (IllegalArgumentException e) {
    // message labels the option ('Service'/'Model') — surface it and stop
    throw new RuntimeException("Invalid typescript-nestjs class suffix: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Passing -DserviceSuffix=.Service or -DmodelSuffix=My-Model (dot or dash), or a suffix with underscores/spaces like '_service'. Thrown from processOpts during generation setup.

Common situations: Reusing the same suffix string for both class and file options (e.g. '.service' works for serviceFileSuffix but fails for serviceSuffix); copying naming conventions from Go/Java generators where dotted suffixes are common.

Related errors


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