Skip to content

Commit

Permalink
Merge pull request #16 from MikeRalphson/exclusives
Browse files Browse the repository at this point in the history
rewrite exclusiveMinimum/exclusiveMaximum
  • Loading branch information
Phil Sturgeon authored Dec 18, 2018
2 parents 142ca43 + 27e0cfe commit 974538d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function convertSchema(schema, path, parent, parentPath) {
schema = stripIllegalKeywords(schema);
schema = convertTypes(schema);
schema = convertDependencies(schema);
schema = rewriteExclusiveMinMax(schema);

if (typeof schema['patternProperties'] === 'object') {
schema = convertPatternProperties(schema);
Expand Down Expand Up @@ -144,4 +145,16 @@ function convertPatternProperties(schema) {
return schema;
}

function rewriteExclusiveMinMax(schema) {
if (typeof schema.exclusiveMaximum === 'number') {
schema.maximum = schema.exclusiveMaximum;
schema.exclusiveMaximum = true;
}
if (typeof schema.exclusiveMinimum === 'number') {
schema.minimum = schema.exclusiveMinimum;
schema.exclusiveMinimum = true;
}
return schema;
}

module.exports = convert;
25 changes: 25 additions & 0 deletions test/exclusiveMinMax.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const convert = require('../');
const should = require('should');

it('exclusiveMinMax', () => {
const schema = {
$schema: 'http://json-schema.org/draft-04/schema#',
type: 'integer',
exclusiveMaximum: 10,
exclusiveMinimum: 0
};

const result = convert(schema);

const expected = {
type: 'integer',
maximum: 10,
exclusiveMaximum: true,
minimum: 0,
exclusiveMinimum: true
};

should(result).deepEqual(expected, 'converted');
});

0 comments on commit 974538d

Please sign in to comment.