fix: complete MICROGRANT #2125 - URL parsing, file extensions, and request validation#2128
fix: complete MICROGRANT #2125 - URL parsing, file extensions, and request validation#2128l8888888 wants to merge 3 commits intoasyncapi:masterfrom
Conversation
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 detectedLatest commit: 81e75de The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this comment.
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.
Note about MICROGRANT #2125I 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
|



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:Solution: Rewrote the URL parsing logic to:
2. File Extension Detection Bug (#1940)
Problem: Used
name.split('.')[1]which fails for:my.asyncapi.yaml→ incorrectly gets "asyncapi" instead of "yaml"asyncapi→ undefined, causes crashSolution:
.pop()to get the last segment after splitting by.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:
requestBody.content['application/json']caused undefined errorsSolution:
content?.['application/json'])Changes
src/domains/services/validation.service.ts: Updated GitHub URL parsing logicsrc/domains/models/SpecificationFile.ts: Fixed file extension detectionsrc/apps/api/middlewares/validation.middleware.ts: Fixed request body validation logicTesting
The fixes handle these cases correctly:
https://github.com/org/repo/blob/feature/new-validation/spec.yamlmy.asyncapi.yamlasyncapi(properly rejected as invalid)Checklist