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

  1. Add unique non-empty operationIds to all operations in the spec.
  2. Pre-fill ids programmatically from method+path before generation (see validationCode).
  3. 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

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


AI-assisted analysis of OpenAPITools/openapi-generator@fcec517be3 (2026-08-22). Data as JSON: /api/errors/0ac0cba23b805f22. Report an issue: GitHub.