{"record":{"id":"34e00504306adfce","repo":"OpenAPITools/openapi-generator","slug":"empty-method-name-operationid-not-allowed-34e005","errorCode":null,"errorMessage":"Empty method name (operationId) not allowed","messagePattern":"Empty method name \\(operationId\\) not allowed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java","lineNumber":934,"sourceCode":"\n    @Override\n    public String toModelDocFilename(String name) {\n        return toModelName(name);\n    }\n\n    @Override\n    public String toApiDocFilename(String name) {\n        return toApiName(name);\n    }\n\n    @Override\n    public String toOperationId(String operationId) {\n        operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);\n\n        // Throw exception if method name is empty.\n        // This should not happen but keep the check just in case\n        if (StringUtils.isEmpty(operationId)) {\n            throw new RuntimeException(\"Empty method name (operationId) not allowed\");\n        }\n\n        // method name cannot use reserved keyword, e.g. return\n        if (isReservedWord(operationId)) {\n            String newOperationId = camelize((\"call_\" + operationId), LOWERCASE_FIRST_LETTER);\n            LOGGER.warn(\"{} (reserved word) cannot be used as method name. Renamed to {}\", operationId, newOperationId);\n            return newOperationId;\n        }\n\n        // operationId starts with a number\n        if (operationId.matches(\"^\\\\d.*\")) {\n            LOGGER.warn(\"{} (starting with a number) cannot be used as method name. Renamed to {}\", operationId, camelize(sanitizeName(\"call_\" + operationId), LOWERCASE_FIRST_LETTER));\n            operationId = camelize(sanitizeName(\"call_\" + operationId), LOWERCASE_FIRST_LETTER);\n        }\n\n        return operationId;\n    }\n","sourceCodeStart":916,"sourceCodeEnd":952,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java#L916-L952","documentation":"The Swift 5 generator derives the method name from operationId via sanitizeName plus camelization. If the result is an empty string — the operationId is missing, blank, or made only of characters that sanitization strips — the generator throws, because a Swift method declaration requires a valid identifier.","triggerScenarios":"An operation in the spec has no operationId (and the derived default sanitizes to nothing), or an operationId consisting only of symbols/whitespace such as '///' or '-'.","commonSituations":"Large specs authored without operationId where a path/method combination produces an empty default; specs exported from converters or gateways that drop operationId for edge-case paths; copy-paste operations where the id was left as a placeholder like '___'.","solutions":["Add an explicit, unique, alphanumeric operationId to the failing operation in the spec.","If an operationId exists but contains only special characters, rename it to a normal identifier.","Add a Spectral lint rule requiring operationId on every operation so this fails in CI before generation."],"exampleFix":"# before\npaths:\n  /pets:\n    get:\n      summary: list pets   # no operationId\n\n# after\npaths:\n  /pets:\n    get:\n      operationId: listPets\n      summary: list pets","handlingStrategy":"validation","validationCode":"// node: every operation must keep a non-empty, sanitizable operationId\nconst hasValidOperationId = (op) =>\n  typeof op.operationId === 'string' && /[a-zA-Z0-9]/.test(op.operationId);\nObject.entries(spec.paths).forEach(([p, item]) =>\n  Object.entries(item).forEach(([m, op]) => {\n    if (['get','put','post','delete','patch','head','options','trace'].includes(m) && !hasValidOperationId(op))\n      throw new Error(`missing operationId at ${m.toUpperCase()} ${p}`);\n  }));","typeGuard":"const isValidOperationId = (id: unknown): id is string =>\n  typeof id === 'string' && /[a-zA-Z0-9]/.test(id);","tryCatchPattern":"// Java\ntry { new DefaultGenerator().opts(input).generate(); }\ncatch (RuntimeException e) {\n    if (e.getMessage().contains(\"operationId\")) { /* add ids to the spec, regenerate once */ }\n}","preventionTips":["Enable the Spectral operation-operationId rule in CI.","Treat operationId as required in your API style guide.","Prefer explicit ids over generator-derived defaults for stable client APIs."],"tags":["swift","openapi","spec-validation","naming"],"backgroundTag":"missing-operation-id","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}