fix(core): fix Ajv error discriminator #2720
fix(core): fix Ajv error discriminator #2720harshit078 wants to merge 19 commits intoRedocly:mainfrom
Conversation
🦋 Changeset detectedLatest commit: f2da64e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
@harshit078 |
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@redocly/respect-core": major | |||
There was a problem hiding this comment.
Please use patch for fixes.
|
@DmitryAnansky sure,
This is my POV of issue. If you think approach can be better, I am ready to implement it. Thanks :) |
There was a problem hiding this comment.
Thanks @harshit078 for the contribution. You don't need to remove discriminator manually, you can just drop this setting from the Ajv and it will not cause the error. The issue looks more deeply. Could you please investigate the root cause?
There was a problem hiding this comment.
sure, I'll look into it
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 8c824f0. Configure here.
| inlineRefs: false, | ||
| validateSchema: false, | ||
| discriminator: true, | ||
| discriminator: false, |
There was a problem hiding this comment.
I’d suggest taking a deeper look into this issue instead of disabling discriminator in Ajv options. It would be worthwhile to review the Ajv implementation and verify how it handles this particular case.

What/Why/How?
remove-discriminators-from-schemawhich just strips discriminator keywords from schemasReference
Testing
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Changes JSON Schema validation behavior by disabling AJV's
discriminatorkeyword, which may alter how some discriminator-based schemas are validated and could surface new example/schema errors that were previously skipped.Overview
Fixes AJV validation failures for OpenAPI schemas that use
discriminatorwith composition patterns (e.g.allOf+not) by disabling AJV’sdiscriminatorkeyword in both the core AJV validator (packages/core/src/rules/ajv.ts) and Respect’s response schema checker (schema-checker.ts).Removes the special-case error swallowing in
validateExampleso discriminator-related AJV errors are now reported instead of silently skipping example validation, and updates/adds tests to assert correct pass/fail behavior for these discriminator schemas.Reviewed by Cursor Bugbot for commit f2da64e. Bugbot is set up for automated code reviews on this repo. Configure here.