Skip to content

fix: resolve GitHub URL parsing and request body validation bugs#2151

Open
jshaofa-ui wants to merge 2 commits intoasyncapi:masterfrom
jshaofa-ui:fix/validation-bugs-1940-1987
Open

fix: resolve GitHub URL parsing and request body validation bugs#2151
jshaofa-ui wants to merge 2 commits intoasyncapi:masterfrom
jshaofa-ui:fix/validation-bugs-1940-1987

Conversation

@jshaofa-ui
Copy link
Copy Markdown

Summary

This PR fixes two bugs identified in the MICROGRANT Program 2026-05:

Bug #1940: CLI fails for GitHub URLs with slash-based branches and multi-dot spec files

Problem 1: GitHub URL Parsing

  • The regex assumed branch names don't contain slashes
  • URLs like https://github.com/org/repo/blob/feature/new-validation/spec.yaml failed with 404
  • Fix: Changed regex to capture branch+path as one group, then use heuristic detection for common branch prefixes (feature, fix, release, etc.) to correctly split branch from file path

Problem 2: File Extension Detection

  • Used name.split('.')[1] which only gets the second segment
  • Files like my.asyncapi.yaml were rejected (got 'asyncapi' instead of 'yaml')
  • Fix: Changed to split('.').pop() to get the last segment

Bug #1987: Request body validation skipped for some paths or HTTP methods

Problem: The compileAjv function only checked application/json content type. Paths using other content types (application/xml, etc.) had validation silently skipped.

Fix: Iterate through all available content types in requestBody.content and use the first one with a valid schema.

Files Changed

  • src/domains/services/validation.service.ts - GitHub URL parsing fix
  • src/domains/models/SpecificationFile.ts - File extension detection fix
  • src/apps/cli/commands/new/file.ts - File extension detection fix
  • src/apps/api/middlewares/validation.middleware.ts - Multi-content-type support

Testing

  • All changes are backward compatible
  • GitHub URL parsing tested with 6 test cases (simple branches, slash-based branches, non-GitHub URLs)
  • File extension detection tested with multi-dot filenames

Related to: #2125 (MICROGRANT Program 2026-05)

- Fix GitHub blob URL parsing to support branches with slashes
  (e.g., feature/new-validation) by using heuristic branch detection
- Fix file extension detection for multi-dot filenames
  (e.g., my.asyncapi.yaml) by using split('.').pop() instead of [1]
- Fix request body validation skipping for non-JSON content types
  by iterating through all available content types

Fixes asyncapi#1940
Fixes asyncapi#1987
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 29, 2026

🦋 Changeset detected

Latest commit: 58b91c8

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

@jshaofa-ui
Copy link
Copy Markdown
Author

🔧 Changeset added! Added to trigger version bump for @asyncapi/cli (patch).

This PR fixes two bugs:

CI checks pass (SonarQube Quality Gate ✅). Ready for review! 🙏

@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.

1 participant