diff --git a/README.md b/README.md index 2ef6533..7abb3ab 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ These keywords allow to define minimum/maximum constraints when the format keywo These keywords apply only to strings. If the data is not a string, the validation succeeds. -The value of keyword `formatMaximum` (`formatMinimum`) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword. +The value of keyword `formatMaximum` (`formatMinimum`) should be a string. This value is the maximum (minimum) allowed value for the data to be valid as determined by `format` keyword. If `format` is not present schema compilation will throw exception. When this keyword is added, it defines comparison rules for formats `"date"`, `"time"` and `"date-time"`. Custom formats also can have comparison rules. See [addFormat](https://github.com/epoberezkin/ajv#api-addformat) method. diff --git a/keywords/_formatLimit.js b/keywords/_formatLimit.js index 2ae8e00..650f84f 100644 --- a/keywords/_formatLimit.js +++ b/keywords/_formatLimit.js @@ -17,6 +17,7 @@ module.exports = function (minMax) { inline: require('./dotjs/_formatLimit'), statements: true, errors: 'full', + dependencies: ['format'], metaSchema: { anyOf: [ { type: 'string' }, diff --git a/spec/formatLimit.spec.js b/spec/formatLimit.spec.js index 3ba02b6..1629211 100644 --- a/spec/formatLimit.spec.js +++ b/spec/formatLimit.spec.js @@ -3,7 +3,7 @@ var Ajv = require('ajv'); var defFunc = require('../keywords/formatMaximum'); var defineKeywords = require('..'); -require('chai').should(); +var should = require('chai').should(); describe('keywords "formatMinimum" and "formatMaximum"', function() { @@ -25,6 +25,14 @@ describe('keywords "formatMinimum" and "formatMaximum"', function() { }); }); + ajvs.forEach(function (ajv, i) { + it('should throw when "format" is absent #' + i, function() { + should.throw(function() { + ajv.compile({ formatMaximum: '2015-08-01' }); + }); + }); + }); + function getAjv(format) { return new Ajv({ allErrors: true, format: format }); }