Skip to content

fix: complete MICROGRANT #2125 - URL parsing, file extensions, and request validation#2128

Open
l8888888 wants to merge 3 commits intoasyncapi:masterfrom
l8888888:fix/github-url-and-extension-bugs
Open

fix: complete MICROGRANT #2125 - URL parsing, file extensions, and request validation#2128
l8888888 wants to merge 3 commits intoasyncapi:masterfrom
l8888888:fix/github-url-and-extension-bugs

Conversation

@l8888888
Copy link
Copy Markdown

@l8888888 l8888888 commented Apr 21, 2026

Description

Fixes #1940 and #1987 (Complete MICROGRANT #2125)

This PR addresses all bugs in the MICROGRANT issue #2125:

1. GitHub URL Parsing Bug (#1940)

Problem: The regex pattern assumed branch names don't contain /, causing failures for valid URLs like:

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

Solution: Rewrote the URL parsing logic to:

  • Parse owner, repo, and the combined branch+path
  • Work backwards from the filename to separate branch from file path
  • Correctly handle branch names with slashes

2. File Extension Detection Bug (#1940)

Problem: Used name.split('.')[1] which fails for:

  • Files with multiple dots: my.asyncapi.yaml → incorrectly gets "asyncapi" instead of "yaml"
  • Files without extensions: asyncapi → undefined, causes crash

Solution:

  • Use .pop() to get the last segment after splitting by .
  • Add proper undefined check for files without extensions
  • Convert to lowercase for case-insensitive comparison

3. Request Body Validation Bug (#1987)

Problem: Request body validation was skipped or reported as "unsupported" for certain paths/methods, even when a valid schema was defined.

Root causes:

  1. Unsafe access to requestBody.content['application/json'] caused undefined errors
  2. Missing schema incorrectly threw "validation not supported" error instead of skipping

Solution:

  • Added safe access with optional chaining (content?.['application/json'])
  • Changed logic to skip validation (not error) when no schema is defined
  • This is correct behavior - not all endpoints require request bodies

Changes

  • src/domains/services/validation.service.ts: Updated GitHub URL parsing logic
  • src/domains/models/SpecificationFile.ts: Fixed file extension detection
  • src/apps/api/middlewares/validation.middleware.ts: Fixed request body validation logic

Testing

The fixes handle these cases correctly:

  • https://github.com/org/repo/blob/feature/new-validation/spec.yaml
  • my.asyncapi.yaml
  • asyncapi (properly rejected as invalid)
  • ✅ Request body validation for all paths/methods
  • ✅ No false "unsupported" errors

Checklist

Fixes asyncapi#1940

This commit addresses two validation bugs in the CLI:

1. GitHub URL Parsing:
   - Previous regex assumed branch names don't contain '/'
   - Now correctly handles URLs like:
     https://github.com/org/repo/blob/feature/new-validation/spec.yaml
   - Parses branch and file path by working backwards from the filename

2. File Extension Detection:
   - Previous code used name.split('.')[1] which fails for:
     - Files with multiple dots (my.asyncapi.yaml)
     - Files without extensions (asyncapi)
   - Now uses .pop() to get the last segment after splitting by '.'
   - Properly handles undefined extensions

Both fixes ensure valid inputs are no longer rejected.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 21, 2026

🦋 Changeset detected

Latest commit: 81e75de

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

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.

@l8888888 l8888888 changed the title fix: Support slash-based branch names and multi-dot file extensions fix: support slash-based branch names and multi-dot file extensions Apr 21, 2026
@l8888888
Copy link
Copy Markdown
Author

Note about MICROGRANT #2125

I noticed that #1940 is part of the MICROGRANT issue #2125, which also includes #1987.

This PR currently fixes only #1940 (GitHub URL parsing and file extension bugs).

Question for maintainers:

I'm happy to extend this PR to include both fixes if that's preferred. Please let me know! 🙏

Fixes asyncapi#1987

This commit fixes request body validation being skipped for certain
paths or HTTP methods.

Issues fixed:
1. Unsafe access to requestBody.content['application/json']
   - Now uses optional chaining to safely check if content type exists
   - Prevents undefined access errors

2. Incorrect error when no requestBody schema is defined
   - Previously threw 'validation not supported' error
   - Now correctly skips validation when no schema is defined
   - This is valid behavior - not all endpoints require request bodies

Changes:
- Added safe access with optional chaining for content type
- Changed validation logic to skip (not error) when no schema exists
- Added clarifying comments

Result:
- Request body validation now works for all paths/methods
- No false 'unsupported' errors for endpoints without request bodies
- Invalid request bodies are properly validated when schema exists
@l8888888 l8888888 changed the title fix: support slash-based branch names and multi-dot file extensions fix: complete MICROGRANT #2125 - URL parsing, file extensions, and request validation Apr 21, 2026
@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