OpenAPITools/openapi-generator · error · RuntimeException
Empty method name (operationId) not allowed
Error message
Empty method name (operationId) not allowed
What it means
AbstractCSharpCodegen.toOperationId throws when the operation name reaching it is null or empty. C# client/interface method names come from operationId; an empty one would produce uncompilable C#, so generation aborts. The comment in code notes this should not occur under normal flow because an auto-generated name is used, so it signals an empty explicit value or a custom code path.
Source
Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java:1537
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + apiPackage();
}
@Override
public String modelFileFolder() {
return outputFolder + File.separator + sourceFolder + File.separator + packageName + File.separator + modelPackage();
}
@Override
public String toModelFilename(String name) {
// should be the same as the model name
return toModelName(name);
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
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)) {
LOGGER.warn("{} (reserved word) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}
return camelize(sanitizeName(operationId));
}
@OverrideView on GitHub (pinned to fcec517be3)
Solutions
- Set a unique non-empty operationId on every operation.
- Delete the empty operationId key rather than leaving a blank value so the default generator can derive a name from the path.
- Audit custom generator subclasses to ensure they never forward empty ids to toOperationId.
Example fix
# before:
paths:
/users/{id}:
get:
operationId: ""
# after:
paths:
/users/{id}:
get:
operationId: getUserById Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: every operation must have a non-empty operationId
OpenAPI api = new OpenAPIV3Parser().read("spec.yaml");
api.getPaths().forEach((path, item) -> item.readOperationsMap().forEach((method, op) -> {
String id = op.getOperationId();
if (id == null || id.trim().isEmpty())
throw new IllegalStateException(method + " " + path + " has an empty operationId");
})); Prevention
- Ensure converter/export tools that produce specs never emit empty operationId strings.
- Never leave 'operationId: ""' — omit the key so a path-derived default is used.
- Validate specs in CI before C# generation runs.
When it happens
Trigger: A spec operation carrying 'operationId: ""' combined with a code path that bypasses default operationId derivation, or a custom C# generator override that calls toOperationId with a blank string.
Common situations: Specs exported from tools that emit empty operationIds; copy-paste spec surgery that strips the id; custom generators built on AbstractCSharpCodegen manipulating ids first.
Related errors
- Empty method/operation name (operationId) not allowed
- Empty method/operation name (operationId) not allowed
- Empty method/operation 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/c7862169061c1160.
Report an issue: GitHub.