{"record":{"id":"4f60a60a9f6dc61f","repo":"OpenAPITools/openapi-generator","slug":"empty-method-operation-name-operationid-not-allo-4f60a6","errorCode":null,"errorMessage":"Empty method/operation name (operationId) not allowed","messagePattern":"Empty method/operation name \\(operationId\\) not allowed","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java","lineNumber":813,"sourceCode":"        if (typeMapping.containsKey(openAPIType)) {\n            type = typeMapping.get(openAPIType);\n            if (!needToImport(type)) {\n                return type;\n            }\n        } else {\n            type = openAPIType;\n        }\n        if (null == type) {\n            LOGGER.error(\"No Type defined for Schema {}\", p);\n        }\n        return toModelName(type);\n    }\n\n    @Override\n    public String toOperationId(String operationId) {\n        // throw exception if method name is empty\n        if (StringUtils.isEmpty(operationId)) {\n            throw new RuntimeException(\"Empty method/operation name (operationId) not allowed\");\n        }\n\n        operationId = camelize(sanitizeName(operationId), LOWERCASE_FIRST_LETTER);\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            String newOperationId = camelize(\"call_\" + operationId, LOWERCASE_FIRST_LETTER);\n            LOGGER.warn(\"{} (starting with a number) cannot be used as method name. Renamed to {}\", operationId, newOperationId);\n            return newOperationId;\n        }\n","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java#L795-L831","documentation":"toOperationId in the javascript-apollo generator refuses an empty or missing operationId instead of synthesizing a method name from method+path as some generators do. It is invoked for every operation during processing, so the first operation lacking an operationId aborts generation with this RuntimeException. The javascript-apollo generator therefore requires every path operation in the OpenAPI document to declare a unique, non-empty operationId.","triggerScenarios":"An OpenAPI document in which any path item operation (get/put/post/delete/options/head/patch/trace) has no operationId or an empty one, passed with `-g javascript-apollo`. Typical with specs produced by converters (Postman exports, Swagger 2.0 upgrades) or hand-merged files that drop ids.","commonSituations":"Hand-written specs where ids were never added; teams merging specs who assume the generator will auto-name operations; specs authored in tools that treat operationId as optional metadata.","solutions":["Add a unique non-empty operationId to every operation in the spec.","Or pre-process the spec to fill ids from method+path before generating (see validationCode).","If specs come from third parties, run an operationId lint (e.g. Spectral operation-operationId-unique plus a presence rule) in CI before invoking the generator."],"exampleFix":"# before (api.yaml)\npaths:\n  /pets:\n    get:\n      summary: list pets\n# after\npaths:\n  /pets:\n    get:\n      operationId: listPets\n      summary: list pets","handlingStrategy":"validation","validationCode":"// Java: fail before generation with a precise location instead of the generator's generic throw\nOpenAPI api = new OpenAPIParser().readLocation(\"api.yaml\", null, new ParseOptions()).getOpenAPI();\napi.getPaths().forEach((path, item) -> item.readOperations().forEach((method, op) -> {\n    if (op == null || org.apache.commons.lang3.StringUtils.isBlank(op.getOperationId())) {\n        throw new IllegalStateException(\"Spec is missing operationId for \" + method.toUpperCase() + \" \" + path\n                + \" — required by javascript-apollo\");\n    }\n}));","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(clientOptInput).generate();\n} catch (RuntimeException e) {\n    // surface which operation is missing an id rather than the bare generator message\n    failBuild(e.getMessage() + \" — run the operationId pre-check to locate the offending path\");\n}","preventionTips":["Lint every spec with Spectral ruleset including operation-operationId-unique plus a presence rule.","Make operationId mandatory in your API style guide and review templates.","Auto-fill ids from method+path in a pre-generation step when third parties supply specs."],"tags":["openapi-generator","javascript","apollo","openapi-spec","operationid"],"backgroundTag":"missing-operationid","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}