OpenAPITools/openapi-generator · error · IllegalArgumentException
%s class prefix only allows alphanumeric characters.
Error message
%s class prefix only allows alphanumeric characters.
What it means
Class-prefix options (apiModulePrefix, configurationPrefix) are validated for alphanumeric-only content, because the prefix is concatenated into generated class names such as ApiModule and Configuration. Non-alphanumeric characters would produce invalid TypeScript identifiers.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java:679
*/
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 validateClassPrefixArgument(String argument, String value) {
if (!value.matches(CLASS_NAME_PREFIX_PATTERN)) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "%s class prefix only allows 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)
);
}View on GitHub (pinned to fcec517be3)
Solutions
- Use a purely alphanumeric prefix, e.g. -DapiModulePrefix=Acme.
- Remove the prefix option to accept the default class names.
Example fix
# before -DapiModulePrefix=acme-api # after -DapiModulePrefix=AcmeApi
Defensive patterns
Strategy: validation
Validate before calling
// node: class prefixes must be alphanumeric
const ALNUM = /^[A-Za-z0-9]+$/;
for (const [k, v] of Object.entries({ apiModulePrefix: opts.apiModulePrefix, configurationPrefix: opts.configurationPrefix }))
if (v && !ALNUM.test(v)) throw new Error(`${k} must be alphanumeric, got: ${v}`); Type guard
const isValidClassPrefix = (v: string): boolean => /^[A-Za-z0-9]+$/.test(v);
Try / catch
// Java
try { new DefaultGenerator().opts(input).generate(); }
catch (IllegalArgumentException e) {
// prefix rejected: sanitize to alphanumeric (strip -._) and rerun
} Prevention
- Treat prefix options as identifier parts, not free text.
- Add a config lint step for naming options before generation.
- Prefer camel- or Pascal-case single-word prefixes.
When it happens
Trigger: -DapiModulePrefix=My-Api or -DconfigurationPrefix=$conf — any prefix matching outside [A-Za-z0-9]+.
Common situations: Using namespace-style prefixes with dots or dashes; pasting vendor prefixes that include symbols; monorepo naming conventions that assume hyphenated module names.
Related errors
- %s file suffix only allows '.', '-' and alphanumeric charact
- %s class suffix only allows alphanumeric characters.
- Invalid file naming '{}'. Must be 'camelCase' or 'kebab-case
- Invalid ngVersion: " + ngVersion + ". Only Angular v9+ is su
- Invalid query param object format '%s'. Must be one of %s.
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/137f272db7449db0.
Report an issue: GitHub.