OpenAPITools/openapi-generator · error · RuntimeException

Empty method/operation name (operationId) not allowed

Error message

Empty method/operation name (operationId) not allowed

What it means

AbstractApexCodegen.toOperationId throws when the operation name reaching it is null or empty. Apex generated classes derive method names from operationId, and an empty name would emit invalid Apex, so generation aborts. The framework normally derives a default operationId from path+method, so an explicitly empty value or a custom code path is what reaches this guard.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractApexCodegen.java:413

        schemaType = getAlias(schemaType);

        // don't apply renaming on types from the typeMapping
        if (typeMapping.containsKey(schemaType)) {
            return typeMapping.get(schemaType);
        }

        if (null == schemaType) {
            LOGGER.error("No Type defined for Property {}", p);
        }
        return toModelName(schemaType);
    }

    @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;
        }

        return operationId;
    }

    @Override
    public CodegenModel fromModel(String name, Schema model) {
        CodegenModel cm = super.fromModel(name, model);

View on GitHub (pinned to fcec517be3)

Solutions

  1. Give every operation a unique non-empty operationId in the spec.
  2. Remove the empty operationId key entirely (instead of leaving it blank) so path-based default naming can kick in.
  3. If you subclass the Apex generator, ensure overrides never pass an empty string into toOperationId.

Example fix

# before:
paths:
  /pets:
    get:
      operationId: ''
# after:
paths:
  /pets:
    get:
      operationId: listPets
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

When it happens

Trigger: An OpenAPI operation whose operationId is an empty string and default derivation was bypassed — e.g. a custom generator overriding fromOperation, or programmatic use calling toOperationId directly with a blank id.

Common situations: Hand-written specs with 'operationId: ""'; specs converted from Postman or API descriptions that drop operationIds; custom Apex generator subclasses that manipulate operationIds before delegation.

Related errors


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