Skip to content

fix(cli): parse GitHub URLs with slash-based branches and multi-dot spec files#2224

Closed
q404365631 wants to merge 2 commits into
asyncapi:masterfrom
q404365631:fix/github-url-parsing-1940
Closed

fix(cli): parse GitHub URLs with slash-based branches and multi-dot spec files#2224
q404365631 wants to merge 2 commits into
asyncapi:masterfrom
q404365631:fix/github-url-parsing-1940

Conversation

@q404365631

Copy link
Copy Markdown

What

Fixes two validation bugs in the CLI described in #1940:

1. GitHub URL parsing (validation.service.ts)

The regex used to convert https://github.com/owner/repo/blob/<branch>/<path> to the GitHub API URL only accepted a single-segment branch, so URLs like

https://github.com/org/repo/blob/feature/new-validation/spec.yaml

were not matched and the API call 404'd. The fix captures everything after /blob/, then heuristically splits off the trailing /<file>.{yaml,yml,json} portion as the file path (with everything before it as the branch). If the trailing portion doesn't have a known spec extension, it falls back to taking the first /-delimited segment as the branch.

2. File extension detection (SpecificationFile.ts)

fileExists() used name.split('.')[1] to extract the extension, which only returned the second segment. A file named spec.test.yaml returned "test" instead of "yaml" and was rejected. Switched to path.extname(name).slice(1).toLowerCase() which correctly returns the last extension.

Why

Both bugs cause valid inputs to fail validation, as reported in #1940.

Changes

  • src/domains/services/validation.service.ts: Replaced the strict single-segment regex in convertGitHubWebUrl() with a more permissive pattern + split heuristic.
  • src/domains/models/SpecificationFile.ts: Replaced name.split('.')[1] with path.extname(name).slice(1).toLowerCase() in fileExists(). path was already imported.

2 files changed, 45 insertions(+), 4 deletions(-).

Testing

Verified manually with the example URLs from the issue:

  • https://github.com/org/repo/blob/feature/new-validation/spec.yaml → resolves to https://api.github.com/repos/org/repo/contents/spec.yaml?ref=feature/new-validation
  • spec.test.yaml → extension correctly detected as yaml

No new automated tests added in this PR to keep it minimal — happy to follow up with a unit test file if the maintainers want.

Closes #1940

Part of MICROGRANT 2026-05 round (#2125).

@changeset-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d3a2c3a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

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

@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

@github-project-automation github-project-automation Bot moved this from To Triage to Done in CLI - Kanban Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] CLI fails for GitHub URLs with slash-based branches and multi-dot spec files

2 participants