Skip to content

Commit

Permalink
fix(rulesets): avoid false errors from ajv
Browse files Browse the repository at this point in the history
This commit modifies the oasExample function so
that example fields are removed from the schema
to be used for validation.  This is needed because
the presence of an "example" field in a schema
confuses ajv in certain scenarios.
References:
- #2081
- #2140
- ajv-validator/ajv#1426
  • Loading branch information
padamstx committed Feb 23, 2023
1 parent 50feb9b commit b33a5ca
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"test.karma": "karma start",
"prepare": "husky install",
"prerelease": "patch-package",
"release": "yarn prerelease && yarn workspaces foreach run release"
"release": "yarn prerelease && yarn workspaces foreach run release",
"jest": "jest"
},
"workspaces": {
"packages": [
Expand Down
5 changes: 4 additions & 1 deletion packages/functions/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export default createRulesetFunction<unknown, Options>(
// let's ignore any $ref errors if schema fn is provided with already resolved content,
// if our resolver fails to resolve them,
// ajv is unlikely to do it either, since it won't have access to the whole document, but a small portion of it
if (!rule.resolved || !(ex instanceof MissingRefError)) {
// We specifically check that "rule" is truthy below because "rule" might be undefined/null if this
// code is called from testcases.
const ignoreError = rule?.resolved && ex instanceof MissingRefError;
if (!ignoreError) {
results.push({
message: ex.message,
path,
Expand Down
Loading

0 comments on commit b33a5ca

Please sign in to comment.