{"record":{"id":"254374358bf3f1ff","repo":"OpenAPITools/openapi-generator","slug":"could-not-generate-api-file-for-tag","errorCode":null,"errorMessage":"Could not generate api file for '{tag}'","messagePattern":"Could not generate api file for '(.+?)'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java","lineNumber":845,"sourceCode":"                            }\n                        }\n                    }\n                }\n\n                // to generate api documentation files\n                for (String templateName : config.apiDocTemplateFiles().keySet()) {\n                    String filename = config.apiDocFilename(templateName, tag);\n                    File written = processTemplateToFile(operation, templateName, filename, generateApiDocumentation, CodegenConstants.API_DOCS);\n                    if (written != null) {\n                        files.add(written);\n                        if (config.isEnablePostProcessFile() && !dryRun) {\n                            config.postProcessFile(written, \"api-doc\");\n                        }\n                    }\n                }\n\n            } catch (Exception e) {\n                throw new RuntimeException(\"Could not generate api file for '\" + tag + \"'\", e);\n            }\n        }\n        if (GlobalSettings.getProperty(\"debugOperations\") != null) {\n            LOGGER.info(\"############ Operation info ############\");\n            Json.prettyPrint(allOperations);\n        }\n\n    }\n\n    void generateWebhooks(List<File> files, List<WebhooksMap> allWebhooks, List<ModelMap> allModels) {\n        if (!generateWebhooks) {\n            // TODO: Process these anyway and present info via dryRun?\n            LOGGER.info(\"Skipping generation of Webhooks.\");\n            return;\n        }\n        Map<String, List<CodegenOperation>> webhooks = processWebhooks(this.openAPI.getWebhooks());\n        Set<String> webhooksToGenerate = getPropertyAsSet(CodegenConstants.WEBHOOKS);\n        if (webhooksToGenerate != null && !webhooksToGenerate.isEmpty()) {","sourceCodeStart":827,"sourceCodeEnd":863,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L827-L863","documentation":"DefaultGenerator.generateApis (line 693) iterates one tag at a time, processes its operations into an OperationsMap and writes the api source, api test and api doc files. Any exception inside that per-tag block - operation conversion, template data assembly, or file writing - is wrapped as RuntimeException with the tag name. Like errors [1]/[2] it is a wrapper: the real cause is the chained exception, and the tag tells you which group of operations to inspect.","triggerScenarios":"Operations under the named tag whose conversion throws: missing operationId where the generator requires one, dangling $ref in parameters/requestBody/responses, security requirements referencing undefined securitySchemes, parameter names colliding after sanitization, unsupported content types; or template-side failures: missing api template in a --template-dir override, custom lambda throwing, unwritable output path for the api file.","commonSituations":"Specs exported from tools that omit operationId; specs split into multiple files where $ref targets a file that failed to resolve; renaming/moving tags so file names collide on case-insensitive filesystems; custom api templates not updated after a generator upgrade added new bundle keys.","solutions":["Read the innermost 'Caused by:' to identify whether it is spec data (conversion NPE) or template/IO.","Open the spec at the operations carrying the failing tag; add missing operationId values, fix $ref targets, and declare any securitySchemes referenced by security requirements.","Run 'openapi-generator-cli validate -i spec.yaml' and fix all diagnostics before regenerating.","If the cause is a missing/unwritable file: restore all api templates in your --template-dir and verify output-folder permissions.","Reduce to a minimal spec containing just the failing tag's operations; if it still fails with a generator-internal stack frame, upgrade openapi-generator or file an issue with the minimal repro."],"exampleFix":"# before\npaths:\n  /pets:\n    get:\n      summary: List pets\n      responses: { '200': { description: ok } }\n# after\npaths:\n  /pets:\n    get:\n      operationId: listPets\n      summary: List pets\n      responses: { '200': { description: ok } }","handlingStrategy":"try-catch","validationCode":"// Ensure every operation has an operationId before generating\nOpenAPI api = ...; // parsed spec\napi.getPaths().forEach((path, item) -> item.readOperations().forEach((method, op) -> {\n    if (op.getOperationId() == null || op.getOperationId().isEmpty()) {\n        throw new IllegalStateException(\"Missing operationId: \" + method + \" \" + path);\n    }\n}));","typeGuard":null,"tryCatchPattern":"try {\n    generator.opts(input).generate();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Could not generate api file\")) {\n        String tag = e.getMessage().split(\"'\")[1];\n        // re-run with only that tag emitted (--global-property apis) to isolate, inspect root cause\n        throw new GenerationFailure(\"API tag failed: \" + tag, e.getCause());\n    }\n    throw e;\n}","preventionTips":["Require operationId in your spec lint rules (spectral rule operation-operationId).","Validate specs with openapi-generator-cli validate before every run.","Keep tags stable and filesystem-safe (no '/', '..', casing-only duplicates)."],"tags":["openapi-generator","openapi","api","tag","code-generation"],"backgroundTag":"openapi-operation-processing-failure","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}