asyncapi / asyncapi/generator

Conditional generation is skipped for nested template paths on Windows

Open
#2,224 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.1k
Forks
397
Avg merge
1d 7h
Merged PRs (30d)
25

Description

### Describe the bug

`conditionalGeneration` (and the deprecated `conditionalFiles`) keys are written with POSIX separators in a template's config, for example `conditionalFolder2/input.txt`. The lookups in `apps/generator/lib/generator.js` build their key with `path.relative`, which returns backslashes on Windows, so a nested key never matches and the condition is silently ignored.

Executed on `win32`:

```
path.relative gives : "conditionalFolder2\input.txt"
config key is : "conditionalFolder2/input.txt"
lookup matches? : false
```

Because the lookup misses, `shouldGenerate` stays `true` and the file is generated even when its condition fails. An end-to-end run against the repository's own test template, with `singleFile: 'true'` (which fails the `enum: ["false"]` validation), shows the top-level cases behaving correctly while the nested one does not:

```
conditionalFile.txt exists (expected false): false
conditionalFolder exists (expected false): false
conditionalFolder2/input.txt exists (expected false): true <-- bug
```

The existing nested-path test only asserts the "should generate" direction, so it passes either way and the regression is invisible on the Windows CI leg.

There is a second, platform-independent part. When a `conditionalFiles` entry matches, the code sets `conditionalPath` to the top-level directory rather than the file key:

```js
conditionalPath = relativeSourceDirectory;
```

so `isGenerationConditionMet` finds no config for that path and returns `undefined`. On POSIX that means a file whose condition **is** met gets skipped. The documented example in `configuration-file.md` uses a nested key, so documented usage is affected.

### Expected behavior

A nested `conditionalGeneration` or `conditionalFiles` key is matched on every platform, and a matching `conditionalFiles` entry is evaluated against its own key.

### How to Reproduce

Run the generator on Windows with a template whose config has a nested `conditionalGeneration` key and a parameter that fails the condition; the file is generated anyway. Output above is from executed runs.

---

I have a fix with regression tests ready and would like to open a PR for this.

Generated-by: Claude Code 2.x

AI assisted in investigating this bug and drafting this issue. I have reviewed and verified the analysis and the reproduction output myself.

Contributor guide

Open the contributing guide

Research direction

Start in apps/generator/lib/generator.js and inspect the path.relative lookup and conditionalPath handling described in the issue. Run the existing nested-path test and reproduce the conditional-generation case on Windows. Done means nested conditionalGeneration and conditionalFiles keys match on every platform and matching file conditions are evaluated correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.