diff --git a/.changeset/fix-external-ref-resolution.md b/.changeset/fix-external-ref-resolution.md new file mode 100644 index 000000000..9b133445f --- /dev/null +++ b/.changeset/fix-external-ref-resolution.md @@ -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. \ No newline at end of file diff --git a/src/domains/services/generator.service.ts b/src/domains/services/generator.service.ts index b24cda8d6..272683e64 100644 --- a/src/domains/services/generator.service.ts +++ b/src/domains/services/generator.service.ts @@ -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; } @@ -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');