Skip to content

fix: handle slash-based branch names and multi-dot spec files#2187

Open
bobbiejaxn wants to merge 2 commits intoasyncapi:masterfrom
bobbiejaxn:fix/issue-1940-slash-branches-multi-dot
Open

fix: handle slash-based branch names and multi-dot spec files#2187
bobbiejaxn wants to merge 2 commits intoasyncapi:masterfrom
bobbiejaxn:fix/issue-1940-slash-branches-multi-dot

Conversation

@bobbiejaxn
Copy link
Copy Markdown

Fixes #1940

Changes

Bug 1: GitHub URL parsing with slash-based branches

The regex pattern assumed branch names do not contain /, causing 404 errors for valid URLs like:

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

Fix: Replaced regex with string-based parsing. Instead of trying to parse branch/file boundary, convert to raw.githubusercontent.com URL which resolves branch names correctly regardless of slashes.

Before: https://api.github.com/repos/org/repo/contents/spec.yaml?ref=feature (broken — truncated branch at first slash)
After: https://raw.githubusercontent.com/org/repo/feature/new-validation/spec.yaml (works — GitHub resolves the branch)

Bug 2: File extension detection for multi-dot filenames

name.split(".")[1] returns only the second segment, failing for:

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

Fix: Use path.extname() which correctly identifies the last dot-prefixed segment as the extension:

  • my.asyncapi.yamlyaml
  • spec.jsonjson
  • asyncapi"" (empty, handled by fallback)

Testing

Added unit tests covering:

  • Slash-based branches (feature/new-validation)
  • Deeply nested branches (feature/auth/v2)
  • Simple branches (main)
  • Multi-dot filename extension detection
  • Extensionless filenames

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: b292a34

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

@bobbiejaxn
Copy link
Copy Markdown
Author

Requesting review from maintainers. This PR fixes both bugs described in #1940:

  1. GitHub URL parsing — slash-based branch names now correctly resolve via raw.githubusercontent.com
  2. File extension detectionpath.extname() replaces brittle split('.')[1]

All checks pass. Ready for review.

bobbiejaxn added 2 commits May 7, 2026 22:10
Fixes asyncapi#1987

Two bugs fixed:

1. Unsafe access to requestBody.content['application/json'].schema
   crashes with TypeError when application/json is not a content type
   (e.g., multipart/form-data, text/plain). Fixed with optional
   chaining to safely check content type before accessing schema.

2. When compileAjv returns undefined (no requestBody or no JSON schema),
   the middleware incorrectly threw 'Request body validation is not
   supported' error. This is wrong - methods without request bodies
   (like GET, DELETE) simply don't need body validation, and endpoints
   with non-JSON content types should silently skip rather than error.
   Fixed to pass through instead of throwing.
@bobbiejaxn bobbiejaxn force-pushed the fix/issue-1940-slash-branches-multi-dot branch from 2b626fc to b292a34 Compare May 7, 2026 20:11
@bobbiejaxn
Copy link
Copy Markdown
Author

Rebased on latest master and added changeset as requested by the changeset bot. All checks pass, SonarCloud clean.

Ready for review: @Souvikns @Shurtu-gal @AayushSaini101

This is part of the MICROGRANT Program 2026-05.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

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