generate:after hook copies AsyncAPI doc verbatim, leaving external $refs unresolvable at client runtime
Describe the bug
The built-in generate:after hook in @asyncapi/generator-hooks (createAsyncapiFile) copies the source AsyncAPI document verbatim into each generated client's output directory as asyncapi.{json,yaml}.
When the source document uses external $refs (e.g. $ref: './commons/servers.yml#/...'), those references are written into the emitted asyncapi.yaml unchanged. Because the referenced sibling files are not copied alongside the generated client, the emitted document is not self-contained — the external refs are unresolvable at client runtime.
This breaks consumers that load the emitted document and compile schemas from it. In particular, @asyncapi/keeper (used by generated clients to validate messages) fails to resolve the external refs, breaking schema compilation on the send path.
How to Reproduce
- Author an AsyncAPI document that splits definitions across files using external
$refs (e.g. aservers.yml/messages.ymlreferenced via./commons/...). - Generate a client with a template that ships the
generate:afterhook. - Inspect the emitted
asyncapi.yamlin the output directory — it still contains external$refs like./commons/servers.yml#/.... - Load that emitted document at runtime (e.g. via
@asyncapi/keeper) — resolution/compilation fails because the referenced files are absent.
Expected behavior
The hook should write a single self-contained document so it is usable standalone next to the generated client — external $refs inlined (bundled). When the source cannot be bundled (string/URL input with no on-disk path, or a bundling failure), it should gracefully fall back to writing the original source unchanged.
Additional context
- Source:
apps/hooks/src/index.js—createAsyncapiFile(generate:after). - Proposed approach: bundle the document via
@asyncapi/bundlerwhen a source file path is available on disk (using the document's own directory asbaseDirso relative external refs resolve correctly), with a fallback to verbatim copy otherwise.
@Adi-204 can i work on it?