Skip to content

fix: handle GitHub URLs with slash-based branches and multi-dot filenames#2203

Open
wdnmdtonyma wants to merge 2 commits into
asyncapi:masterfrom
wdnmdtonyma:fix/github-url-and-extension-parsing
Open

fix: handle GitHub URLs with slash-based branches and multi-dot filenames#2203
wdnmdtonyma wants to merge 2 commits into
asyncapi:masterfrom
wdnmdtonyma:fix/github-url-and-extension-parsing

Conversation

@wdnmdtonyma
Copy link
Copy Markdown

Summary

Fixes #1940

This PR fixes two validation bugs in the CLI:

1. GitHub URL Parsing (slash-based branches)

Before: The regex ([^\/]+) for branch capture failed on branches with slashes (e.g., feature/new-validation), causing 404 errors.

After: Captures everything after /blob/ and converts to raw.githubusercontent.com URL, which resolves the branch/path ambiguity internally. This correctly handles:

  • https://github.com/org/repo/blob/feature/new-validation/spec.yaml
  • https://github.com/org/repo/blob/main/spec.yaml (still works)

2. File Extension Detection (multi-dot filenames)

Before: name.split('.')[1] extracted the wrong segment for multi-dot filenames:

  • my.asyncapi.yaml → extracted asyncapi instead of yaml
  • asyncapi (no extension) → extracted undefined

After: Uses parts.pop() to correctly extract the last extension:

  • my.asyncapi.yaml → extracts yaml
  • asyncapi (no extension) → handled gracefully ✓

Files Changed

  • src/domains/services/validation.service.ts — GitHub URL conversion
  • src/domains/models/SpecificationFile.tsfileExists() extension check
  • src/apps/cli/commands/new/file.tscreateAsyncapiFile() extension check

How to Test

# Test 1: GitHub URL with slash-branch (should no longer 404)
asyncapi validate https://github.com/org/repo/blob/feature/branch/spec.yaml

# Test 2: Multi-dot filename
asyncapi validate my.asyncapi.yaml

# Test 3: Existing behavior still works
asyncapi validate spec.yaml
asyncapi validate https://github.com/org/repo/blob/main/spec.yaml

…ames

Fixes asyncapi#1940

1. GitHub URL parsing: Changed from regex with `[^\/]+` for branch capture
   (which fails on branches like `feature/new-validation`) to capturing
   everything after `/blob/` and converting to raw.githubusercontent.com
   URL, which resolves branch/path ambiguity internally.

2. File extension detection: Changed `name.split('.')[1]` to
   `parts.pop()` to correctly extract the last extension segment.
   This fixes handling of multi-dot filenames like `my.asyncapi.yaml`
   (previously extracted `asyncapi` instead of `yaml`) and filenames
   without extensions.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2026

🦋 Changeset detected

Latest commit: 0511ad6

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
Copy link
Copy Markdown

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] CLI fails for GitHub URLs with slash-based branches and multi-dot spec files

1 participant