Skip to content

Commit

Permalink
feat: make "format" a dependency of "formatMaximum/Minimum"
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Feb 9, 2019
1 parent da6e030 commit bdcf858
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions keywords/_formatLimit.js
Expand Up @@ -17,6 +17,7 @@ module.exports = function (minMax) {
inline: require('./dotjs/_formatLimit'),
statements: true,
errors: 'full',
dependencies: ['format'],
metaSchema: {
anyOf: [
{ type: 'string' },
Expand Down
10 changes: 9 additions & 1 deletion spec/formatLimit.spec.js
Expand Up @@ -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() {
Expand All @@ -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 });
}
Expand Down

0 comments on commit bdcf858

Please sign in to comment.