OpenAPITools/openapi-generator · error · RuntimeException
" + operationId + " (reserved word) cannot be used as method
Error message
" + operationId + " (reserved word) cannot be used as method name
What it means
The scalaz client generator's toOperationId() rejects operationIds that are Scala reserved words, because the generated Scalaz/http4s client method could not be declared with that name in Scala. The RuntimeException names the offending word.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalazClientCodegen.java:219
public String getName() {
return "scalaz";
}
@Override
public String getHelp() {
return "Generates a Scalaz client library (beta) that uses http4s";
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
}
return camelize(operationId, LOWERCASE_FIRST_LETTER);
}
private static abstract class CustomLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment frag, Writer out) throws IOException {
final StringWriter tempWriter = new StringWriter();
frag.execute(tempWriter);
out.write(formatFragment(tempWriter.toString()));
}
public abstract String formatFragment(String fragment);
}
private class EnumEntryLambda extends CustomLambda {
@OverrideView on GitHub (pinned to fcec517be3)
Solutions
- Rename the operationId to a non-reserved word, ideally verb+noun (fetchType, buildObject)
- Check the generator's reserved word list (reservedWords() in the Scala codegens) when picking ids
- Add a CI lint step that rejects Scala reserved words in operationIds for Scala targets
Example fix
# before
paths:
/schema:
get:
operationId: type
# after
paths:
/schema:
get:
operationId: getType Defensive patterns
Strategy: validation
Validate before calling
# Reject Scala reserved words as operationIds (Python):
SCALA_RESERVED = {'abstract','case','catch','class','def','do','else','extends','false','final',
'finally','for','forSome','if','implicit','import','lazy','match','new','null',
'object','override','package','private','protected','return','sealed','super',
'this','throw','trait','true','try','type','val','var','while','with','yield'}
for oid in all_operation_ids(spec):
assert oid not in SCALA_RESERVED, f'operationId {oid!r} is a Scala reserved word' Try / catch
try {
new DefaultGenerator().opts(input).generate();
} catch (RuntimeException e) {
// '<word> (reserved word) cannot be used as method name' - rename that operationId and rerun
} Prevention
- Avoid single-keyword operationIds, especially Scala-only keywords like type, object, trait, implicit
- Shared multi-language specs should lint against the union of target-language reserved words
- camelize() will not rescue a bare keyword; only a rename fixes it
When it happens
Trigger: -g scalaz on a spec with operationId: type / object / return / package / trait / match / implicit / lazy, etc. Single-word ids are not changed by camelize(operationId, LOWERCASE_FIRST_LETTER), so they reach the check intact.
Common situations: Operation ids mirroring domain verbs that collide with Scala keywords; specs shared across language generators where only the Scala one fails; keyword lists differing between Java and Scala (e.g. 'type', 'object', 'trait', 'implicit' fail here though they are legal elsewhere).
Related errors
- " + operationId + " (reserved word) cannot be used as method
- Empty method name (operationId) not allowed
- Empty method name (operationId) not allowed
- DateLibrary " + dateLibrary + " is not supported. Please use
- unsupported status " + resp.code
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/83a706dd0a5ec4e5.
Report an issue: GitHub.