OpenAPITools/openapi-generator · error · RuntimeException

Empty method/operation name (operationId) not allowed

Error message

Empty method/operation name (operationId) not allowed

What it means

AbstractKotlinCodegen.toOperationId throws when the operation name reaching it is null or empty. Kotlin function names in the generated client/server code come from operationId; an empty one would produce invalid Kotlin, so generation aborts. A path-derived default normally prevents this, so it indicates an explicit blank or a custom code path.

Source

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

                    modelName);
            return modelName;
        }

        schemaKeyToModelNameCache.put(name, titleCase(modifiedName));
        return schemaKeyToModelNameCache.get(name);
    }

    /**
     * Return the operation ID (method name)
     *
     * @param operationId operation ID
     * @return the sanitized method name
     */
    @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), LOWERCASE_FIRST_LETTER);
            operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER);
        }

        return operationId;
    }

View on GitHub (pinned to fcec517be3)

Solutions

  1. Give every operation a unique non-empty operationId.
  2. Remove the empty operationId key entirely so the default name is derived from path+method.
  3. Ensure custom generator overrides never pass empty strings 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: A spec operation with 'operationId: ""' processed where default derivation is bypassed, or a custom Kotlin generator calling toOperationId directly with an empty id.

Common situations: Specs produced by converters that blank operationIds; hand-edited specs; generator subclasses that preprocess operation ids.

Related errors


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