Repository navigation
fix: ensure request body validation works for all content types and paths - #2207
XuanYuandp wants to merge 4 commits into
Conversation
…le extensions Fixes asyncapi#1940 Two bugs fixed: 1. GitHub URL parsing regex assumed branch names don't contain '/'. This caused URLs like github.com/org/repo/blob/feature/new-validation/spec.yaml to be incorrectly parsed, extracting only 'feature' as the branch name. Fixed by using a heuristic to find the correct branch/path split point. 2. File extension detection used `name.split('.')[1]` which returns the wrong segment for multi-dot filenames like `my.asyncapi.yaml`. Fixed by using `.pop()` to always get the last segment (actual extension). Files changed: - src/domains/services/validation.service.ts: Fix GitHub URL regex - src/domains/models/SpecificationFile.ts: Fix extension detection - src/apps/cli/commands/new/file.ts: Fix extension detection - test/unit/services/validation.service.test.ts: Add test for slash branches
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…aths Fixes asyncapi#1987 Three issues fixed: 1. Content type lookup was hardcoded to 'application/json' only. The code now iterates over all content types to find the schema, supporting any content-type defined in the OpenAPI spec. 2. No null safety on requestBody.content - dereferencing could leave content as undefined, causing TypeError that silently skipped validation. Added explicit null check. 3. The condition callback in convert controller skipped ALL validation (both body and document) when condition was false. Now it only skips body validation while still performing document validation. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 176daca 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 |
|
|
This pull request has been automatically marked as stale because it has not had recent activity 😴 It will be closed in 120 days if no further activity occurs. To unstale this pull request, add a comment with detailed explanation. There can be many reasons why some specific pull request has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model. Let us figure out together how to push this pull request forward. Connect with us through one of many communication channels we established here. Thank you for your patience ❤️ |



What this does
Fixes #1987 — Request body validation was being skipped for certain paths or HTTP methods even when a valid request body schema was defined.
Bug 1: Hardcoded content type
The code only looked at
requestBody.content['application/json']. If the OpenAPI spec defined the request body under a different content type, validation was skipped entirely.Fix: Iterate over all content types to find the schema.
Bug 2: No null safety on content
After OpenAPI dereferencing,
requestBody.contentcould be undefined, causing a TypeError that silently skipped validation.Fix: Added explicit null check on
content.Bug 3: condition callback skipped ALL validation
The
conditioncallback in the convert controller caused both body validation AND AsyncAPI document validation to be completely skipped when the condition was false.Fix: Now only skips body validation while still performing document validation.
Files changed
src/apps/api/middlewares/validation.middleware.tsTesting
All 9 existing tests passing. No regressions.
Part of MICROGRANT Program 2026-05.