fix(core): fix Ajv error discriminator #2720
fix(core): fix Ajv error discriminator #2720harshit078 wants to merge 28 commits intoRedocly:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 9ce2215 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 :) |
| strictSchema: false, | ||
| inlineRefs: false, | ||
| validateSchema: false, | ||
| discriminator: true, |
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
| 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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
There are 3 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c3ac165. Configure here.
|
Hi, @harshit078 |
|
Hey @DmitryAnansky , https://github.com/ajv-validator/ajv/blob/master/lib/vocabularies/discriminator/index.ts |

What/Why/How?
remove-discriminators-from-schemawhich just strips discriminator keywords from schemasReference
Testing
Screenshots (optional)
Check yourself
Security
Note
Medium Risk
Touches core response schema validation behavior; while the change is targeted, normalizing schemas could affect edge-case discriminator matching or validation outcomes if the promoted
const/enumis ambiguous.Overview
Fixes AJV discriminator validation crashes by preprocessing dereferenced schemas so discriminator tag properties expose
const/enumat the top level even when they’re nested insideallOf(while keeping the originalallOfconstraints intact).checkSchemanow runs schemas through the newnormalizeDiscriminatorSchemasutility before AJV validation, and tests were added/updated to coveroneOf/anyOfdiscriminators withallOf + notpatterns and to ensure failures are reported as normal validation errors (notAjv error).Reviewed by Cursor Bugbot for commit 9ce2215. Bugbot is set up for automated code reviews on this repo. Configure here.