OpenAPITools/openapi-generator · error · IllegalArgumentException

Invalid file naming '{}'. Must be 'camelCase' or 'kebab-case

Error message

Invalid file naming '{}'. Must be 'camelCase' or 'kebab-case'

What it means

The typescript-nestjs server generator's setFileNaming (TypeScriptNestjsServerCodegen.java:594) accepts only 'camelCase' or 'kebab-case' for the 'fileNaming' option, which controls model file name derivation. Any other string throws this IllegalArgumentException during processOpts because the generator has no implementation for other naming strategies.

Source

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

     */
    private void validateClassSuffixArgument(String argument, String value) {
        if (value != null && !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'");
        }
    }

    /**
     * Converts the original name according to the current <code>fileNaming</code> strategy.
     *
     * @param originalName the original name to transform
     * @return the transformed name
     */
    private String convertUsingFileNamingConvention(String originalName) {
        String name = this.removeModelPrefixSuffix(originalName);
        if ("kebab-case".equals(fileNaming)) {
            name = dashize(underscore(name));
        } else {
            name = camelize(name, LOWERCASE_FIRST_LETTER);
        }
        return name;

View on GitHub (pinned to fcec517be3)

Solutions

  1. Set -DfileNaming=camelCase or -DfileNaming=kebab-case exactly.
  2. Remove the fileNaming key entirely if the default behavior is fine.

Example fix

# before
openapi-generator-cli generate -g typescript-nestjs-server -DfileNaming=PascalCase

# after
openapi-generator-cli generate -g typescript-nestjs-server -DfileNaming=camelCase
Defensive patterns

Strategy: validation

Validate before calling

case "$FILE_NAMING" in
  camelCase|kebab-case|"") ;;
  *) echo "ERROR: fileNaming must be 'camelCase' or 'kebab-case'" >&2; exit 1;;
esac

Type guard

const isFileNaming = (v: string): v is 'camelCase' | 'kebab-case' =>
  v === 'camelCase' || v === 'kebab-case';

Prevention

When it happens

Trigger: Generating with -DfileNaming=snake_case, -DfileNaming=camelcase (wrong casing), or a value copy-pasted from another generator's docs. Exact string match is required.

Common situations: Reusing a shared options file between typescript-nestjs (client) and other language generators; spec files that embed a fileNaming vendor extension with a value valid elsewhere; CI templates parameterizing naming style.

Related errors


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