OpenAPITools/openapi-generator · error · RuntimeException

Empty method name (operationId) not allowed

Error message

Empty method name (operationId) not allowed

What it means

The PowerShell client's toOperationId() throws a RuntimeException when the operationId it receives is empty (PowerShellClientCodegen.java:983). The code comment notes this 'should not occur' because the core pipeline auto-generates a method name from path+method when operationId is absent — so an explicit empty-string operationId (or a direct programmatic call) is what trips it.

Source

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

     */
    @Override
    public String getTypeDeclaration(Schema p) {
        if (ModelUtils.isArraySchema(p)) {
            Schema inner = ModelUtils.getSchemaItems(p);
            return getTypeDeclaration(inner) + "[]";
        } else if (ModelUtils.isMapSchema(p)) {
            return "System.Collections.Hashtable";
        } else if (!languageSpecificPrimitives.contains(getSchemaType(p))) {
            return super.getTypeDeclaration(p);
        }
        return super.getTypeDeclaration(p);
    }

    @Override
    public String toOperationId(String operationId) {
        // throw exception if method name is empty (should not occur as an auto-generated method name will be used)
        if (StringUtils.isEmpty(operationId)) {
            throw new RuntimeException("Empty method name (operationId) not allowed");
        }

        return sanitizeName(operationId);
    }

    @Override
    public String toParamName(String name) {
        // obtain the name from parameterNameMapping directly if provided
        if (parameterNameMapping.containsKey(name)) {
            return parameterNameMapping.get(name);
        }

        // sanitize and camelize parameter name
        // pet_id => PetId
        name = camelize(sanitizeName(name));

        // for param name reserved word or word starting with number, append _
        if (paramNameReservedWords.contains(name) || name.matches("^\\d.*")) {

View on GitHub (pinned to fcec517be3)

Solutions

  1. Set a unique non-empty operationId on every operation.
  2. Delete the empty `operationId:` key so the auto-generation fallback can name the method.
  3. Lint specs for empty-string operationIds in CI before code generation.

Example fix

# before (api.yaml)
paths:
  /users/{id}:
    delete:
      operationId: ""
      responses: { '204': { description: deleted } }
# after
paths:
  /users/{id}:
    delete:
      operationId: deleteUser
      responses: { '204': { description: deleted } }
Defensive patterns

Strategy: validation

Validate before calling

// powershell: empty-string operationIds break toOperationId; absent ones are synthesized
openAPI.getPaths().forEach((path, item) -> {
  for (Operation op : item.readOperations().values()) {
    if (op.getOperationId() != null && op.getOperationId().trim().isEmpty()) {
      throw new IllegalArgumentException("Empty operationId on " + path
          + " — set a value or remove the key");
    }
  }
});

Try / catch

try {
    new DefaultGenerator().opts(clientOptInput).generate();
} catch (RuntimeException e) {
    throw new BuildException("PowerShell generation failed: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Generating `-g powershell` from a spec with `operationId: ""` on an operation; or calling PowerShellClientCodegen.toOperationId("") directly in embedded generation code.

Common situations: Templated specs where operationId is left blank for later filling; pipelines merging specs where a merge key overwrites operationId with an empty anchor; upstream API exports that emit empty operationIds for undocumented endpoints.

Related errors


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