OpenAPITools/openapi-generator · error · RuntimeException

Empty method/operation name (operationId) not allowed

Error message

Empty method/operation name (operationId) not allowed

What it means

AbstractJavaCodegen.toOperationId throws when the operation name reaching it is null or empty. Java interface/client method names are derived from operationId, and an empty one would generate invalid Java, so the run aborts. The framework normally supplies a path-derived default, so this fires when an explicitly empty value or a custom code path bypasses that.

Source

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

    public String getSchemaType(Schema p) {
        String openAPIType = super.getSchemaType(p);

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

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

    @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.*")) {
            LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + operationId), true);
            operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
        }

        return operationId;

View on GitHub (pinned to fcec517be3)

Solutions

  1. Assign a unique non-empty operationId to every operation.
  2. Remove the blank operationId key so the default path-based name is generated.
  3. In custom subclasses, guard against passing empty strings into toOperationId.

Example fix

# before:
paths:
  /orders:
    delete:
      operationId: ''
# after:
paths:
  /orders:
    delete:
      operationId: deleteOrder
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: A spec operation with 'operationId: ""' processed through a code path that skips default derivation, or a custom Java generator subclass calling toOperationId with a blank id.

Common situations: Specs converted from other formats that emit blank operationIds; hand-edited specs; generator subclasses that sanitize/replace ids and can produce empty strings for exotic path names.

Related errors


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