[BUG] Missing CSS/JS when generating without `singleFile`
Describe the bug.
When generating docs with @asyncapi/html-template version 3.3.0+, the generated index.html references CSS and JS files, but they are not created in the output folder when singleFile is not used.
With 3.2.0, both singleFile=true and singleFile=false modes worked correctly. Starting with 3.3.0, only singleFile=true works.
[!TIP] I suspect the issue is with the new conditional generation added.
Expected behavior
- If singleFile=true: generate one standalone HTML file with bundled CSS/JS (works fine in 3.3.1 also).
- If singleFile=false (or not passed): generate index.html + referenced css/ and js/ assets (broken in 3.3.0+).
Screenshots
How to Reproduce
-
Run:
./bin/run generate fromTemplate asyncapi.yaml @asyncapi/html-template -o ../docs --use-new-generator --force-write -
Example spec (simplified):
asyncapi: 3.0.0
info:
title: Account Service
version: 1.0.0
channels:
userSignedup:
address: user/signedup
messages:
UserSignedUp:
$ref: '#/components/messages/UserSignedUp'
components:
messages:
UserSignedUp:
payload:
type: object
properties:
email:
type: string
-
Open the generated index.html in the browser.
-
Notice that it references CSS/JS files, but none are generated.
🖥️ Device Information [optional]
- Operating System (OS):
- Browser:
- Browser Version:
👀 Have you checked for similar open issues?
- [x] I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- [x] I have read the Contributing Guidelines
Are you willing to work on this issue ?
None
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
I have the same issue.
Versions of asyncapi/html-template/generator are bellow:
$ asyncapi --version
@asyncapi/cli/3.5.2 linux-x64 node-v24.7.0
$ npm list -g @asyncapi/html-template
/home/georgii/.nvm/versions/node/v24.7.0/lib
└─┬ @asyncapi/[email protected]
└─┬ generator-v2@npm:@asyncapi/[email protected]
└── @asyncapi/[email protected]
is it still valid?? I would like to work on this @Shurtu-gal
I believe so.
okay I'm working on it
I think it is working now not an bug anymore
I think it is working now not an bug anymore
Please try with version 3.3.0
@Shurtu-gal I tried using html-template version 3.3.0. The CSS and JS files are generated, but index.html isn’t referencing them. It only contains inline script and CSS instead of linking to the external files.
but you said, When generating docs with @asyncapi/html-template version 3.3.0+, the generated index.html references CSS and JS files, but they are not created in the output folder when singleFile is not used.
the command I used : asyncapi generate fromTemplate asyncapi.yaml @asyncapi/[email protected] --use-new-generator -o output -p singleFile=false
Am i doing something wrong?
No that might also be an issue.
@Shurtu-gal I have checked with version 3.3.0 by cloning the repo and switching to branch v3.3.1
this is package.json
example.yml is the code you provided and generated the output using command npm run test:example
I'm not getting any error
Yeah, test won't give the error. To reproduce it, need to run with generator.
checked with latest 3.3.1
Problem might be in https://github.com/asyncapi/generator/blob/master/apps/generator/lib/templates/config/loader.js#L47. Tests should be checked for loadDefaultValues.
in html-template config https://github.com/asyncapi/html-template/blob/master/package.json#L90-L93 singleFile default is false. So if you do not pass this parameter, false value should be injected with context into generation process.
This false default value is critical for another setting (conditional generation): https://github.com/asyncapi/html-template/blob/master/package.json#L63-L75 which means that required css and js folders will be rendered in output only fi singleFile is set to false.
asyncapi generate fromTemplate test/spec/asyncapi_v3.yml ./ -o dupa --use-new-generator --force-write -p singleFile=false works as expected, false goes through, so directories are there. Of course flah singleFile=true works as well.
Problem is that during generation in case like asyncapi generate fromTemplate test/spec/asyncapi_v3.yml ./ -o dupa --use-new-generator --force-write the template gets singleFile as undefined (doesn't get it at all). I can only see the following defaults
{
"outFilename": "index.html",
"pdfTimeout": 30000
}
So there is for sure a bug in generator, it is not handling default values set to false
hey @Shurtu-gal @derberg I think there might be a small mismatch in how the command is being run... Right now, the generator expects
singleFileas a string, so the CLI usage should be:-p singleFile="false"not:
-p singleFile=falseThat is also consistent with how
.ageneratorrcis defined in the generator repo, for example here we use:enum: ["false"] #and many more places..I’ve already opened a PR to fix
loadDefaultValuesso that default values likefalseare correctly applied. After that fix, the defaultsingleFile: falseworks as expected, but:false==="false" // output will always be falseso
-p singleFile=false(boolean-like) won’t match theconst: "false"in the template config.Do you expect both forms to work:
-p singleFile=false # boolean-like -p singleFile="false" # stringor is the intended contract that only the string
"false"is supported via CLI?If the goal is for both to work, the solution is ready!! just waiting for your call!
i think i got the solution for it, whether it is string or boolean. But I am still waiting for you guys to responed.. Based on your feedback, i will create the PR!! or whatever you guys recommend...🫡
Edit: Since there’s already a PR open, I’ll help guide her toward the correct path instead of opening a duplicate
Hi, I’m new to the project and would like to work on this issue. Is it still open and okay for me to take it?
Hi, I'm new here to this project and would like to contribute to fix this issue. Is it still open to work on ?
Hello @derberg is this issue open? Can I work on it?
:tada: This issue has been resolved in version 3.5.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
it is fixed but requires people to use latest generator @asyncapi/[email protected] so if anyone wanna use the fix, need to make sure lates generator is bumped in https://github.com/asyncapi/cli