Skip to content

fix: resolve external $refs from subdirectories, add registry timeout, and fix browserslist error#2092

Open
ljapptest-art wants to merge 1 commit intoasyncapi:masterfrom
ljapptest-art:bounty/asyncapi-cli-2039
Open

fix: resolve external $refs from subdirectories, add registry timeout, and fix browserslist error#2092
ljapptest-art wants to merge 1 commit intoasyncapi:masterfrom
ljapptest-art:bounty/asyncapi-cli-2039

Conversation

@ljapptest-art
Copy link
Copy Markdown

Summary

This PR fixes three issues from the AsyncAPI Bounty Program 2026-04:

Issue #1839: External $refs from subdirectories not resolved correctly

Problem: When an AsyncAPI file is located in a subdirectory (e.g., ./src/contract/asyncapi.yaml), relative $ref references to external files were not being resolved correctly.

Solution: Modified Specification.fromFile() to convert relative file paths to absolute paths using path.resolve(). This ensures that the parser can correctly resolve relative $ref references from the file's actual directory.

Issue #2027: CLI hangs with unreachable registry URL

Problem: When using --registry-url with an unreachable host, the CLI would hang indefinitely without any timeout or error message.

Solution: Added a 5-second timeout using AbortController to the registry URL validation. Also changed from GET to HEAD request for a more lightweight check and improved error messages to be more informative.

Issue #1781: Browserslist error with pnpm

Problem: When using pnpm to generate documentation, browserslist would incorrectly parse shell wrapper scripts (created by pnpm in node_modules/.bin/) as config files, causing errors like Unknown browser query 'basedir=$(dirname "$(echo "$0"....

Solution: Set BROWSERSLIST_DISABLE_CACHE=1 environment variable in the generator service to prevent browserslist from looking for config files in unexpected locations.

Changes

  • src/domains/models/SpecificationFile.ts: Convert relative paths to absolute paths in fromFile()
  • src/utils/generate/registry.ts: Add timeout and improved error handling for registry validation
  • src/domains/services/generator.service.ts: Disable browserslist cache to prevent pnpm-related errors
  • Added unit tests for the changes

Testing

  • Added test/unit/utils/registry.test.ts for registry validation tests
  • Added test/unit/models/SpecificationFile.test.ts for specification file path resolution tests

Fixes #1839, fixes #2027, fixes #1781

Bounty: AsyncAPI Bounty Program 2026-04 (Issue #2039)

…, and fix browserslist error

- Fix issue asyncapi#1839: Convert relative file paths to absolute paths in
  Specification.fromFile() to ensure external $refs are resolved from
  the correct base directory when AsyncAPI files are in subdirectories.

- Fix issue asyncapi#2027: Add 5-second timeout to registry URL validation with
  AbortController, use HEAD request for lightweight checks, and provide
  better error messages for unreachable servers.

- Fix issue asyncapi#1781: Set BROWSERSLIST_DISABLE_CACHE environment variable to
  prevent browserslist from incorrectly parsing pnpm shell wrapper
  scripts as config files.

Bounty: AsyncAPI Bounty Program 2026-04 (Issue asyncapi#2039)
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

⚠️ No Changeset found

Latest commit: b538028

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide 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.

@sonarqubecloud
Copy link
Copy Markdown

@ljapptest-art ljapptest-art marked this pull request as ready for review March 30, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Triage

1 participant