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 of the plain javascript generator throws when an operation's operationId is null or empty rather than auto-generating a method name. It runs for every operation, so a single id-less operation aborts the whole generation run with a RuntimeException.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java:843
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 unique non-empty operationIds to all operations in the spec.
- Pre-fill ids programmatically from method+path before generation (see validationCode).
- Add a CI spec-lint step (Spectral operation-operationId-unique plus a presence check) so bad specs fail before the generator runs.
Example fix
# before (api.yaml)
/users/{id}:
delete:
summary: remove user
# after
/users/{id}:
delete:
operationId: deleteUser
summary: remove user Defensive patterns
Strategy: validation
Validate before calling
// Java: pre-check every operation for an id before running the javascript generator
OpenAPI api = new OpenAPIParser().readLocation("api.yaml", null, new ParseOptions()).getOpenAPI();
List<String> missing = new ArrayList<>();
api.getPaths().forEach((path, item) -> item.readOperationsMap().forEach((m, op) -> {
if (op.getOperationId() == null || op.getOperationId().isBlank()) missing.add(m.name() + " " + path);
}));
if (!missing.isEmpty()) throw new IllegalStateException("Operations missing operationId: " + missing); Try / catch
try {
new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
failBuild("Spec rejected (likely missing operationId): " + e.getMessage());
} Prevention
- Enforce operationId presence in CI with a Spectral/custom lint step before generation.
- Treat 'Empty method/operation name' as a spec defect, not a CLI problem.
- When merging spec fragments, run the pre-check to catch id-less additions early.
When it happens
Trigger: `-g javascript` against a spec where any operation lacks operationId (or has operationId: ""); specs converted from Swagger 2.0 or Postman that drop ids; specs assembled from multiple files where one fragment omits ids.
Common situations: Large hand-maintained specs where a new endpoint was added without an id; API-first pipelines that never enforced operationId presence.
Related errors
- Empty method/operation name (operationId) not allowed
- Empty method/operation name (operationId) not allowed
- Empty method name (operationId) not allowed
- Empty method/operation name (operationId) not allowed
- Empty method name (operationId) not allowed
AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22).
Data as JSON: /api/errors/0ac0cba23b805f22.
Report an issue: GitHub.