OpenAPITools/openapi-generator · error · RuntimeException

Empty method name (operationId) not allowed

Error message

Empty method name (operationId) not allowed

What it means

The Swift Combine generator applies the same guard as the other Swift generators: the method name is computed from operationId by sanitization and camelization, and an empty result throws because a valid Swift identifier is required for the generated API method.

Source

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

    @Override
    public String toModelDocFilename(String name) {
        return toModelName(name);
    }

    @Override
    public String toApiDocFilename(String name) {
        return toApiName(name);
    }

    @Override
    public String toOperationId(String operationId) {
        operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);

        // Throw exception if method name is empty.
        // This should not happen but keep the check just in case
        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)) {
            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("{} (starting with a number) cannot be used as method name. Renamed to {}", operationId, camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER));
            operationId = camelize(sanitizeName("call_" + operationId), LOWERCASE_FIRST_LETTER);
        }


        return operationId;
    }

View on GitHub (pinned to fcec517be3)

Solutions

  1. Give the failing operation an explicit alphanumeric operationId.
  2. Fix or remove placeholder operationIds made of symbols.
  3. Run a spec linter that requires operationId before invoking the generator.

Example fix

# before
paths:
  /feed:
    get:
      operationId: ''

# after
paths:
  /feed:
    get:
      operationId: getFeed
Defensive patterns

Strategy: validation

Validate before calling

// node
const requiresId = (op) => Boolean(op && op.responses);
Object.values(spec.paths).forEach(item =>
  Object.values(item).forEach(op => {
    if (requiresId(op) && !/[a-zA-Z0-9]/.test(String(op.operationId ?? '')))
      throw new Error('operation missing usable operationId');
  }));

Type guard

const isValidOperationId = (id: unknown): id is string =>
  typeof id === 'string' && /[a-zA-Z0-9]/.test(id);

Try / catch

// Java
try { new DefaultGenerator().opts(input).generate(); }
catch (RuntimeException e) {
    // empty operationId after sanitize: patch spec and regenerate once
}

Prevention

When it happens

Trigger: An operation with a missing, blank, or symbol-only operationId whose sanitized and camelized form is the empty string.

Common situations: Switching the Combine generator on for an old spec that lacks operationIds; specs edited by hand where an operationId was accidentally emptied; API-portal exports that omit operationId for auto-generated routes.

Related errors


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