@readme/better-ajv-errors
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -129,2 +129,5 @@ "use strict"; | ||
case 'pattern': | ||
return ret.concat(new _validationErrors.PatternValidationError(error, options)); | ||
case 'required': | ||
@@ -131,0 +134,0 @@ return ret.concat(new _validationErrors.RequiredValidationError(error, options)); |
@@ -17,2 +17,4 @@ "use strict"; | ||
var _openapiSchemas = require("@apidevtools/openapi-schemas"); | ||
describe('Main', function () { | ||
@@ -111,6 +113,8 @@ it('should support js output format for default errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
}, _callee3); | ||
}))); | ||
it('should support js output format for unevaluatedProperties errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() { | ||
var _yield$getSchemaAndDa7, _yield$getSchemaAndDa8, schema, data, ajv, validate, valid, res; | ||
}))); // Though this is testing `patternProperties` cases, the error that'll come back will just be for `pattern` since | ||
// that's what `patternPropeties` utilizes in the schema. | ||
it('should support js output format for patternProperties errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() { | ||
var _yield$getSchemaAndDa7, _yield$getSchemaAndDa8, data, schema, ajv, validate, valid, res; | ||
return _regenerator["default"].wrap(function _callee4$(_context4) { | ||
@@ -121,3 +125,3 @@ while (1) { | ||
_context4.next = 2; | ||
return (0, _testHelpers.getSchemaAndData)('unevaluatedProperties', __dirname); | ||
return (0, _testHelpers.getSchemaAndData)('patternProperties', __dirname); | ||
@@ -127,5 +131,11 @@ case 2: | ||
_yield$getSchemaAndDa8 = (0, _slicedToArray2["default"])(_yield$getSchemaAndDa7, 2); | ||
schema = _yield$getSchemaAndDa8[0]; | ||
data = _yield$getSchemaAndDa8[1]; | ||
ajv = new _["default"](); | ||
// The OpenAPI 3.1 schema has a good example of this for component names so we're using that instead of writing | ||
// our own. | ||
schema = _openapiSchemas.openapi.v31; | ||
ajv = new _["default"]({ | ||
allErrors: true, | ||
strict: false, | ||
validateFormats: false | ||
}); | ||
validate = ajv.compile(schema); | ||
@@ -146,3 +156,3 @@ valid = validate(data); | ||
}))); | ||
it('should support js output format for enum errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() { | ||
it('should support js output format for unevaluatedProperties errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() { | ||
var _yield$getSchemaAndDa9, _yield$getSchemaAndDa10, schema, data, ajv, validate, valid, res; | ||
@@ -155,3 +165,3 @@ | ||
_context5.next = 2; | ||
return (0, _testHelpers.getSchemaAndData)('enum', __dirname); | ||
return (0, _testHelpers.getSchemaAndData)('unevaluatedProperties', __dirname); | ||
@@ -179,2 +189,33 @@ case 2: | ||
}))); | ||
it('should support js output format for enum errors', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() { | ||
var _yield$getSchemaAndDa11, _yield$getSchemaAndDa12, schema, data, ajv, validate, valid, res; | ||
return _regenerator["default"].wrap(function _callee6$(_context6) { | ||
while (1) { | ||
switch (_context6.prev = _context6.next) { | ||
case 0: | ||
_context6.next = 2; | ||
return (0, _testHelpers.getSchemaAndData)('enum', __dirname); | ||
case 2: | ||
_yield$getSchemaAndDa11 = _context6.sent; | ||
_yield$getSchemaAndDa12 = (0, _slicedToArray2["default"])(_yield$getSchemaAndDa11, 2); | ||
schema = _yield$getSchemaAndDa12[0]; | ||
data = _yield$getSchemaAndDa12[1]; | ||
ajv = new _["default"](); | ||
validate = ajv.compile(schema); | ||
valid = validate(data); | ||
expect(valid).toBe(false); | ||
res = (0, _2["default"])(schema, data, validate.errors, { | ||
format: 'js' | ||
}); | ||
expect(res).toMatchSnapshot(); | ||
case 12: | ||
case "end": | ||
return _context6.stop(); | ||
} | ||
} | ||
}, _callee6); | ||
}))); | ||
}); |
@@ -63,3 +63,3 @@ "use strict"; | ||
var chalk = this.getChalk(); | ||
var output = [chalk(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["{red {bold ADDTIONAL PROPERTY} ", "}\n"], ["{red {bold ADDTIONAL PROPERTY} ", "}\\n"])), message)]; | ||
var output = [chalk(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["{red {bold ADDITIONAL PROPERTY} ", "}\n"], ["{red {bold ADDITIONAL PROPERTY} ", "}\\n"])), message)]; | ||
return output.concat(this.getCodeFrame(chalk(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2["default"])(["\uD83D\uDE32 {magentaBright ", "} is not expected to be here!"])), params.additionalProperty), "".concat(this.instancePath, "/").concat(params.additionalProperty))); | ||
@@ -66,0 +66,0 @@ } |
@@ -26,2 +26,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "PatternValidationError", { | ||
enumerable: true, | ||
get: function get() { | ||
return _pattern["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "RequiredValidationError", { | ||
@@ -40,10 +46,12 @@ enumerable: true, | ||
var _required = _interopRequireDefault(require("./required")); | ||
var _additionalProp = _interopRequireDefault(require("./additional-prop")); | ||
var _default = _interopRequireDefault(require("./default")); | ||
var _enum = _interopRequireDefault(require("./enum")); | ||
var _default = _interopRequireDefault(require("./default")); | ||
var _pattern = _interopRequireDefault(require("./pattern")); | ||
var _required = _interopRequireDefault(require("./required")); | ||
var _unevaluatedProp = _interopRequireDefault(require("./unevaluated-prop")); |
{ | ||
"name": "@readme/better-ajv-errors", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "JSON Schema validation for Human", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96500
28
1872