OpenAPITools/openapi-generator · error · IllegalArgumentException

recallScope key cannot be empty

Error message

recallScope key cannot be empty

What it means

RecallLambda (registered as 'recall' and 'recallOnce' by AbstractCSharpCodegen for C# generators) looks up previously cached content by the trimmed body of {{#recall}}key{{/recall}}. If that body trims to an empty string there is nothing to look up, and an IllegalArgumentException is thrown to stop silent no-op recalls in generated output. A missing key in the cache is NOT an error (the lambda writes nothing), only an empty key is.

Source

Thrown at modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/RecallLambda.java:45

 * Writes rendered text that was previously cached by key.
 *
 * Syntax:
 * {{#recallScope}}key{{/recallScope}}
 */
public class RecallLambda implements Mustache.Lambda {
    private final CacheContent cacheContent;
    private final boolean clear;

    public RecallLambda(CacheContent cacheContent, boolean clear) {
        this.cacheContent = cacheContent;
        this.clear = clear;
    }

    @Override
    public void execute(Fragment fragment, Writer writer) throws IOException {
        String key = fragment.execute().trim();
        if (key.isEmpty()) {
            throw new IllegalArgumentException("recallScope key cannot be empty");
        }

        String content = this.cacheContent.contentByKey.get(key);
        if (content == null) {
            return;
        }

        if (this.clear) {
            this.cacheContent.contentByKey.remove(key);
        }

        writer.write(content);
    }
}

View on GitHub (pinned to fcec517be3)

Solutions

  1. Fill the recall block with a literal key: {{#recall}}userModel{{/recall}}.
  2. If the key is a variable, guard the block so it only renders when the variable is non-empty.
  3. Cross-check that every {{#recall}} key matches a key used in a prior {{#cache}} block.

Example fix

{{! before }}
{{#recall}}{{modelName}}{{/recall}}
{{! (renders empty when modelName is empty) }}

{{! after }}
{{#hasModelName}}{{#recall}}{{modelName}}{{/recall}}{{/hasModelName}}
{{! or a literal key: }}
{{#recall}}userModel{{/recall}}
Defensive patterns

Strategy: validation

Validate before calling

# lint: reject recall blocks whose body is empty or whitespace-only
grep -rnE '\{\{#(recall|recallOnce)\}\}[[:space:]]*\{\{/' templates/ && {
  echo "ERROR: recall key cannot be empty" >&2; exit 1;
}

Prevention

When it happens

Trigger: A template containing {{#recall}} {{/recall}} or {{#recallOnce}}\n{{/recallOnce}} — whitespace-only or blank body. Typically happens when the key inside the block comes from a variable that renders empty, e.g. {{#recall}}{{someEmptyVar}}{{/recall}}.

Common situations: Templating cache keys off model properties that are occasionally empty (empty title, empty vendorExtension value); refactoring templates and leaving a recall block as a placeholder; copy-paste of a recall block followed by deleting its key.

Related errors


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