Skip to content

fix(build): skip redundant AsyncAPI examples fetching when cached - #2285

Open
RohithPariki wants to merge 1 commit into
asyncapi:masterfrom
RohithPariki:fix/issue-2015-skip-redundant-example-fetch
Open

fix(build): skip redundant AsyncAPI examples fetching when cached#2285
RohithPariki wants to merge 1 commit into
asyncapi:masterfrom
RohithPariki:fix/issue-2015-skip-redundant-example-fetch

Conversation

@RohithPariki

Copy link
Copy Markdown

Problem

During the build process (npm run build), scripts/fetch-asyncapi-example.js unconditionally downloaded the examples ZIP file from GitHub, extracted it, and parsed every spec file to generate assets/examples/examples.json.
This network operation ran on every single build, causing:

  • Unnecessary network traffic and slower local build times.
  • Flaky builds if GitHub or the network was temporarily unreachable or offline even when examples were already present.

Root Cause

scripts/fetch-asyncapi-example.js executed immediately without verifying whether assets/examples/examples.json and the example YAML specs already existed in the local filesystem.

Solution

  1. Added shouldSkipFetching() check to verify if assets/examples/examples.json exists, is non-empty, and example YAML files are present in the directory.
  2. Added manual override support via --force, -f, or FORCE_FETCH_EXAMPLES=true environment variable so developers and CI can force re-fetching when needed.
  3. Added unit tests in test/unit/scripts/fetch-asyncapi-example.test.ts covering all caching conditions, empty files, missing files, and forced overrides.

Testing

  • Added and ran unit test test/unit/scripts/fetch-asyncapi-example.test.ts (6 passing tests).
  • Verified node scripts/fetch-asyncapi-example.js skips when examples are present.
  • Verified node scripts/fetch-asyncapi-example.js --force downloads fresh examples.
  • Ran npm run build and npm run lint.

Risk

None. If examples.json does not exist or is invalid, the script falls back to downloading as before.

Checklist

  • Tests pass locally
  • Lint passes
  • Matches existing code conventions
  • Regression tests added

Fixes #2015

@changeset-bot

changeset-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fdb9d43

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

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

@RohithPariki
RohithPariki marked this pull request as ready for review August 29, 2026 02:06
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

Development

Successfully merging this pull request may close these issues.

[BUG] Optimizing build process: Skip redundant AsyncAPI examples fetching

1 participant