OpenAPITools/openapi-generator · error · RuntimeException

Could not generate supporting file '{support}'

Error message

Could not generate supporting file '{support}'

What it means

generateSupportingFiles iterates config.supportingFiles(); each SupportingFile is resolved to an output filename and rendered via processTemplateToFile. Any exception in that block - template file not found in the template engine, template rendering error, or IOException while writing - is wrapped with support.toString() (the supporting file's destination path). The chained cause tells you whether it is a missing template, a rendering failure on the bundle data, or a filesystem error.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java:1128

                        once(LOGGER).debug("Output directory {} not created. It {}.", outputFolder, of.exists() ? "already exists." : "may not have appropriate permissions.");
                    }
                }


                boolean shouldGenerate = true;
                if (supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
                    shouldGenerate = supportingFilesToGenerate.contains(support.getDestinationFilename());
                }

                File written = processTemplateToFile(bundle, support.getTemplateFile(), outputFilename, shouldGenerate, CodegenConstants.SUPPORTING_FILES);
                if (written != null) {
                    files.add(written);
                    if (config.isEnablePostProcessFile() && !dryRun) {
                        config.postProcessFile(written, "supporting-file");
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException("Could not generate supporting file '" + support + "'", e);
            }
        }

        // Consider .openapi-generator-ignore a supporting file
        // Output .openapi-generator-ignore if it doesn't exist and wasn't explicitly created by a generator
        // and the option openapiGeneratorIgnoreList is not set
        if (config.openapiGeneratorIgnoreList() == null || config.openapiGeneratorIgnoreList().isEmpty()) {
            final String openapiGeneratorIgnore = ".openapi-generator-ignore";
            String ignoreFileNameTarget = config.outputFolder() + File.separator + openapiGeneratorIgnore;
            File ignoreFile = new File(ignoreFileNameTarget);
            if (generateMetadata) {
                try {
                    boolean shouldGenerate = !ignoreFile.exists();
                    if (shouldGenerate && supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
                        shouldGenerate = supportingFilesToGenerate.contains(openapiGeneratorIgnore);
                    }
                    File written = processTemplateToFile(bundle, openapiGeneratorIgnore, ignoreFileNameTarget, shouldGenerate, CodegenConstants.SUPPORTING_FILES);
                    if (written != null) {

View on GitHub (pinned to fcec517be3)

Solutions

  1. Identify the failing supporting file from the message path, then look up which template name it maps to in the generator's supportingFiles() definition.
  2. Check the chained cause: FileNotFoundException/<template>.mustache => copy that template from the generator's bundled resources into your --template-dir; IOException => fix output-directory permissions/space.
  3. Keep --template-dir overrides complete: re-copy ALL templates from the matching generator version whenever you upgrade, then re-apply your edits.
  4. If you do not need the file, add its destination path to .openapi-generator-ignore - processTemplateToFile skips ignored targets entirely, so generation proceeds without rendering it.
  5. For scope-related failures, run full scope (no --global-property filter) or adjust the custom template to tolerate empty operation/model lists.

Example fix

# before: template override missing pom.hbs -> 'pom.xml' supporting file fails
# after: copy the missing template from the generator jar into the override
cp ~/.m2/repository/org/openapi-generator/openapi-generator/6.x/y
# (illustrative) unzip -p openapi-generator-6.x.jar Java/pom.mustache > my-tpl/pom.mustache
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: every supporting-file template must resolve in the template dir
String overrideDir = config.getTemplateDir();
for (SupportingFile sf : config.supportingFiles()) {
    if (overrideDir != null && !Files.exists(Path.of(overrideDir, sf.getTemplateFile()))) {
        throw new IllegalStateException(
            "Missing template for supporting file: " + sf.getTemplateFile());
    }
}

Try / catch

try {
    generator.opts(input).generate();
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Could not generate supporting file")) {
        String target = e.getMessage().split("'")[1];
        if (e.getCause() instanceof java.io.FileNotFoundException
                || e.getCause() instanceof java.io.IOException) {
            // add target to .openapi-generator-ignore or restore template, then retry
        }
        throw new GenerationFailure("Supporting file failed: " + target, e.getCause());
    }
    throw e;
}

Prevention

When it happens

Trigger: A SupportingFile whose templateFile is absent from a --template-dir override (classic partial-copy mistake); a custom template using a lambda or key that is missing from the bundle for the current run scope (e.g. --global-property apis only, so operations/models lists are empty); an output filename containing characters illegal on the OS; unwritable output directory; template engine classpath problems (missing handlebars adapter when engine id is set).

Common situations: Teams overriding a subset of templates and the generator release adds NEW supporting files whose templates the override lacks; custom generators shipping a supportingFiles() entry without the corresponding resource; CI running with a narrower scope (--global-property) than the templates were written for.

Related errors


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