Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/fix-external-ref-resolution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@asyncapi/cli": patch
---

fix: resolve external $ref files relative to spec file location

When the CLI was refactored to use GeneratorService, the `path` option passed to `generator.generateFromString()` was accidentally changed from a string file path to a Specification object. This caused relative `$ref` paths to be resolved against CWD instead of the spec file's directory.

This fix passes `asyncapi.getSource()` (which returns the file path string or URL) instead of the Specification object, restoring the correct behavior for resolving external file references.
4 changes: 2 additions & 2 deletions src/domains/services/generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getErrorMessage } from '@utils/error-handler';
* Options passed to the generator for code generation.
*/
interface GeneratorRunOptions {
path?: Specification;
path?: string;
[key: string]: unknown;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export class GeneratorService extends BaseService {
try {
await generator.generateFromString(asyncapi.text(), {
...genOption,
path: asyncapi,
path: asyncapi.getSource(),
});
} catch (err: unknown) {
s.stop('Generation failed');
Expand Down
Loading