OpenAPITools/openapi-generator · error · RuntimeException

Empty method name (operationId) not allowed

Error message

Empty method name (operationId) not allowed

What it means

AbstractPhpCodegen.toOperationId throws when the operation name reaching it is null or empty. PHP method names in the generated API classes derive from operationId; an empty one would generate invalid PHP, so the run aborts. Default operationId derivation from path+method normally prevents blank ids from reaching this code.

Source

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

    public String toAbstractName(final String name) {
        return camelize(abstractNamePrefix + name + abstractNameSuffix);
    }

    /**
     * Output the proper trait name (capitalized).
     *
     * @param name the name of the trait
     * @return capitalized trait name
     */
    public String toTraitName(final String name) {
        return camelize(traitNamePrefix + name + traitNameSuffix);
    }

    @Override
    public String toOperationId(String operationId) {
        // throw exception if method name is empty
        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), LOWERCASE_FIRST_LETTER));
            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), LOWERCASE_FIRST_LETTER));
            operationId = "call_" + operationId;
        }

        return camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);
    }

    /**

View on GitHub (pinned to fcec517be3)

Solutions

  1. Set a unique non-empty operationId on every operation.
  2. Delete the blank operationId key so the generator derives a name from the path.
  3. Check custom generator overrides for empty-id forwarding.

Example fix

# before:
paths:
  /items:
    put:
      operationId: ''
# after:
paths:
  /items:
    put:
      operationId: updateItem
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 carrying 'operationId: ""' where default derivation is bypassed, or a custom PHP generator calling toOperationId with a blank string.

Common situations: Machine-converted specs that drop operationIds; manually pruned specs; generator subclasses on AbstractPhpCodegen that rewrite ids first.

Related errors


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