Skip to content
This repository has been archived by the owner on Feb 7, 2025. It is now read-only.

Commit

Permalink
feat: expose the total amount of validation schema errors (#254)
Browse files Browse the repository at this point in the history
* feat: expose the total amount of validation schema errors

* fix: broken test?

* fix: broken test???

* fix: try again????
  • Loading branch information
erunion authored Apr 18, 2024
1 parent 99807aa commit 115ddda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/validators/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function validateSchema(api, options) {

let additionalErrors = 0;
let reducedErrors = reduceAjvErrors(err);
const totalErrors = reducedErrors.length;
if (reducedErrors.length >= LARGE_SPEC_ERROR_CAP) {
try {
if (JSON.stringify(api).length >= LARGE_SPEC_SIZE_CAP) {
Expand All @@ -92,7 +93,7 @@ function validateSchema(api, options) {
message += `Plus an additional ${additionalErrors} errors. Please resolve the above and re-run validation to see more.`;
}

throw ono.syntax(err, { details: err }, message);
throw ono.syntax(err, { details: err, totalErrors }, message);
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/specs/validate-schema/validate-schema.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('Invalid APIs (Swagger 2.0 and OpenAPI 3.x schema validation)', () => {
expect(err.message).to.match(/^OpenAPI schema validation failed.\n(.*)+/);

expect(err.details).to.be.an('array').to.have.length(3);
expect(err.totalErrors).to.equal(2);

expect(err.message).to.contain("REQUIRED must have required property 'url'");
expect(err.message).to.contain('url is missing here');
Expand Down Expand Up @@ -161,6 +162,7 @@ describe('Invalid APIs (Swagger 2.0 and OpenAPI 3.x schema validation)', () => {
}

expect(err.details).to.be.an('array').with.length.above(0);
expect(err.totalErrors).to.be.at.least(1);

// Make sure the Ajv error details object is valid
const details = err.details[0];
Expand Down

0 comments on commit 115ddda

Please sign in to comment.