feat: content-type support for validateResponse/validateRequest#1
Merged
Conversation
Narrow stored options type to { strict: boolean } since contentType
is resolved per-call, not at construction time.
Extend extractResponseSchema with an optional contentType parameter (defaulting to application/json) that uses isBinaryContentType and resolveMediaType to support exact, family-wildcard, and */* media-type matching; silently bypasses unmatched binary types and emits MISSING_SCHEMA for unmatched non-binary types.
Extend extractRequestSchema with an optional contentType parameter (defaulting to application/json), using resolveMediaType for wildcard matching and isBinaryContentType for silent bypass of binary payloads. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Plumbs options.contentType (defaulting to 'application/json') from validateResponse into extractResponseSchema, enabling content-type-aware schema lookup for binary and wildcard media types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update normalizeAllSchemas to iterate over every media-type object in both response content and requestBody content, rather than only handling application/json, so non-JSON schemas (multipart/form-data, text/plain, etc.) are also converted to OpenAPI 3.1 shape during init. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace nullable-based assertions (which Ajv silently accepts even without normalization due to strict:false) with exclusiveMinimum boolean-form tests that only pass when normalizeAllSchemas actually rewrites 3.0 schemas under non-JSON content types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
contentTypetoValidatorOptions; defaults toapplication/json(no breaking changes).image/*) →*/*.MISSING_SCHEMAwarnings for binary mocks like QR codes.normalizeAllSchemasnow rewrites 3.0 → 3.1 schemas under every media-type entry, not onlyapplication/json.Spec:
specs.md(2026-04-20). This is rollout step 1 of 3;twd-cliandtwddepend on this.Test plan
npm test— 144 tests pass (9 files)npm run build— clean TypeScript compilenormalizeAllSchemasactually runs over non-JSON content types (uses 3.0exclusiveMinimum: trueboolean form which Ajv rejects without normalization).new OpenAPIMockValidator(spec).validateResponse('/qr', 'get', 200, bytes, { contentType: 'image/png' })returns{ valid: true, warnings: [] }when spec declaresimage/jpeg.🤖 Generated with Claude Code