OpenAPITools/openapi-generator · error · RuntimeException
Empty method/operation name (operationId) not allowed
Error message
Empty method/operation name (operationId) not allowed
What it means
toOperationId in the javascript-apollo generator refuses an empty or missing operationId instead of synthesizing a method name from method+path as some generators do. It is invoked for every operation during processing, so the first operation lacking an operationId aborts generation with this RuntimeException. The javascript-apollo generator therefore requires every path operation in the OpenAPI document to declare a unique, non-empty operationId.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java:813
if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
if (!needToImport(type)) {
return type;
}
} else {
type = openAPIType;
}
if (null == type) {
LOGGER.error("No Type defined for Schema {}", p);
}
return toModelName(type);
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
}
operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, newOperationId);
return newOperationId;
}
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
String newOperationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, newOperationId);
return newOperationId;
}
View on GitHub (pinned to fcec517be3)
Solutions
- Add a unique non-empty operationId to every operation in the spec.
- Or pre-process the spec to fill ids from method+path before generating (see validationCode).
- If specs come from third parties, run an operationId lint (e.g. Spectral operation-operationId-unique plus a presence rule) in CI before invoking the generator.
Example fix
# before (api.yaml)
paths:
/pets:
get:
summary: list pets
# after
paths:
/pets:
get:
operationId: listPets
summary: list pets Defensive patterns
Strategy: validation
Validate before calling
// Java: fail before generation with a precise location instead of the generator's generic throw
OpenAPI api = new OpenAPIParser().readLocation("api.yaml", null, new ParseOptions()).getOpenAPI();
api.getPaths().forEach((path, item) -> item.readOperations().forEach((method, op) -> {
if (op == null || org.apache.commons.lang3.StringUtils.isBlank(op.getOperationId())) {
throw new IllegalStateException("Spec is missing operationId for " + method.toUpperCase() + " " + path
+ " — required by javascript-apollo");
}
})); Try / catch
try {
new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
// surface which operation is missing an id rather than the bare generator message
failBuild(e.getMessage() + " — run the operationId pre-check to locate the offending path");
} Prevention
- Lint every spec with Spectral ruleset including operation-operationId-unique plus a presence rule.
- Make operationId mandatory in your API style guide and review templates.
- Auto-fill ids from method+path in a pre-generation step when third parties supply specs.
When it happens
Trigger: An OpenAPI document in which any path item operation (get/put/post/delete/options/head/patch/trace) has no operationId or an empty one, passed with `-g javascript-apollo`. Typical with specs produced by converters (Postman exports, Swagger 2.0 upgrades) or hand-merged files that drop ids.
Common situations: Hand-written specs where ids were never added; teams merging specs who assume the generator will auto-name operations; specs authored in tools that treat operationId as optional metadata.
Related errors
- Empty method/operation name (operationId) not allowed
- Empty method/operation name (operationId) not allowed
- Invalid model property naming '{name}'. Must be 'original',
- Invalid model property naming '{naming}'. Must be 'original'
- Empty method name (operationId) not allowed
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/4f60a60a9f6dc61f.
Report an issue: GitHub.