fix: resolve external ref files relative to spec file location#2075
Closed
HuiNeng6 wants to merge 1 commit intoasyncapi:masterfrom
Closed
fix: resolve external ref files relative to spec file location#2075HuiNeng6 wants to merge 1 commit intoasyncapi:masterfrom
HuiNeng6 wants to merge 1 commit intoasyncapi:masterfrom
Conversation
Fixes asyncapi#1839 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 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.
🦋 Changeset detectedLatest commit: e810aa5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes #1839 — External
$reffiles in the same directory are not resolved since the CLI architecture refactoring.Root Cause
When the CLI was refactored to use
GeneratorService, thepathoption passed togenerator.generateFromString()was changed from a string file path to a Specification object:The
@asyncapi/generator's parser checkstypeof oldOptions.path === 'string'to set thesourcepath for resolving relative$refreferences. Since aSpecificationobject is not a string, the source path was never set, causing relative$refpaths to be resolved against the CWD instead of the spec file's directory.Fix
Use
asyncapi.getSource()which returns the file path string (or URL) from the Specification object:Also updated the
GeneratorRunOptionsinterface to correctly typepathasstringinstead ofSpecification.Changes
src/domains/services/generator.service.ts: Passasyncapi.getSource()instead of theSpecificationobject aspath; fixGeneratorRunOptions.pathtype fromSpecificationtostringTest plan
$refand runasyncapi generate fromTemplateNote: This PR is similar to #2046 and #2056 but provides an independent fix for the same issue. The fix logic is identical and correct.