{"record":{"id":"64f9be91fd436b1a","repo":"OpenAPITools/openapi-generator","slug":"name","errorCode":null,"errorMessage":"{name}","messagePattern":"\\{name\\}","errorType":"exception","errorClass":"TemplateNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/TemplateManager.java","lineNumber":66,"sourceCode":"     */\n    public TemplateManager(\n            TemplateManagerOptions options,\n            TemplatingEngineAdapter engineAdapter,\n            TemplatePathLocator[] templateLoaders) {\n        this.options = options;\n        this.engineAdapter = engineAdapter;\n        this.templateLoaders = templateLoaders;\n    }\n\n    private String getFullTemplateFile(String name) {\n        String template = Arrays.stream(this.templateLoaders)\n                .map(i -> i.getFullTemplatePath(name))\n                .filter(Objects::nonNull)\n                .findFirst()\n                .orElse(\"\");\n\n        if (StringUtils.isEmpty(template)) {\n            throw new TemplateNotFoundException(name);\n        }\n\n        if (name == null || name.contains(\"..\")) {\n            throw new IllegalArgumentException(\"Template location must be constrained to template directory.\");\n        }\n\n        return template;\n    }\n\n    /**\n     * returns the template content by name\n     *\n     * @param name the template name (e.g. model.mustache)\n     * @return the contents of that template\n     */\n    @Override\n    public String getFullTemplateContents(String name) {\n        String fullPath = getFullTemplateFile(name);","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/TemplateManager.java#L48-L84","documentation":"TemplateManager.getFullTemplateFile() asks every configured template loader for a full path for the template name; if all return null it throws TemplateNotFoundException. This means neither the classpath bundles nor the user-supplied template directory (-t/--template-dir) contain a file with that name. It typically surfaces when a generator or user requests a template that was never shipped or whose custom copy is misnamed.","triggerScenarios":"Running with --template-dir myTemplates where a generator expects e.g. model.mustache/modelDoc.mustache but the directory only overrides some templates without the base library ones (classpath usually covers those, so in practice this fires for templates the classpath also lacks, e.g. a custom generator's private template name); requesting a renamed template via additional properties; case-sensitivity mismatch on case-sensitive filesystems.","commonSituations":"Custom generator JARs whose templates are not on the classpath; template directories copied from a different generator (Go templates used for a Java generator); filename typos like modelTemplate.mustache vs model.mustache; upgrading generators where a template was renamed.","solutions":["Verify the exact template filename the generator requests (enable debug logging on TemplateManager) and create/rename the file in your template directory to match.","Point -t at the directory that actually contains the template and confirm the path is correct.","If using a custom generator, ensure its template resources are packaged and on the classpath.","Check filename case on Linux/macOS builds — mismatches that worked on Windows fail elsewhere."],"exampleFix":"# before\n--template-dir ./tpl   # ./tpl only contains api.mustache, generator also needs model.mustache elsewhere\n# after\n# copy the generator's default templates into ./tpl first, then override:\ncp -r modules/openapi-generator/src/main/resources/<lang>/ ./tpl/\n--template-dir ./tpl","handlingStrategy":"validation","validationCode":"// Ensure required templates exist before invoking generation\nString[] required = {\"model.mustache\", \"api.mustache\"};\nfor (String t : required) {\n    if (!Files.exists(Paths.get(templateDir, t))\n            && getClass().getClassLoader().getResource(\"templates/\" + t) == null) {\n        throw new FileNotFoundException(\"Missing template: \" + t);\n    }\n}","typeGuard":null,"tryCatchPattern":"Catch TemplateNotFoundException specifically; distinguish it from other generation failures and report as a template-packaging problem (no retry).","preventionTips":["Start custom template dirs from a copy of the generator's shipped templates, then override selectively.","Pin generator versions so template names stay stable.","Test custom template sets in CI on a case-sensitive filesystem."],"tags":["openapi","template","code-generation","file-not-found"],"backgroundTag":"missing-template-file","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}