fix: resolve schema validation bug where errors were swallowed - #2831
Open
karansaini46 wants to merge 1 commit into
Open
fix: resolve schema validation bug where errors were swallowed#2831karansaini46 wants to merge 1 commit into
karansaini46 wants to merge 1 commit into
Conversation
This fixes issue stoplightio#2442 where an invalid schema would cause the validation proxy to always pass silently because the compilation error from Ajv was swallowed by O.tryCatch.
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.
Closes #2442.
What was the problem?
When providing an invalid OpenAPI schema (e.g.
type: obj), the validation proxy was silently swallowing the Ajv compilation error and proceeding to pass the request/response validation. The issue stems from the use ofO.tryCatch, which caught the schema error but simply returnedO.none, meaning 'no errors'.What changed?
Refactored
validateAgainstSchemato useE.tryCatchso we capture the error from Ajv compilation instead of losing it. The error is now correctly folded into anIPrismDiagnosticwith a severity ofErrorand a generic code500. Also added a regression test for invalid schema objects.Why this approach was chosen?
Using
E.tryCatchkeeps the functional programming approach consistent while exposing the error properly as an array of Prism Diagnostics, matching the expected return type and reporting to the user properly.