Skip to content

Commit 27e0cfe

Browse files
committed
rewrite exclusiveMinimum/exclusiveMaximum
1 parent 17e4ffc commit 27e0cfe

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

index.js

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function convertSchema(schema, path, parent, parentPath) {
3030
schema = stripIllegalKeywords(schema);
3131
schema = convertTypes(schema);
3232
schema = convertDependencies(schema);
33+
schema = rewriteExclusiveMinMax(schema);
3334

3435
if (typeof schema['patternProperties'] === 'object') {
3536
schema = convertPatternProperties(schema);
@@ -140,4 +141,16 @@ function convertPatternProperties(schema) {
140141
return schema;
141142
}
142143

144+
function rewriteExclusiveMinMax(schema) {
145+
if (typeof schema.exclusiveMaximum === 'number') {
146+
schema.maximum = schema.exclusiveMaximum;
147+
schema.exclusiveMaximum = true;
148+
}
149+
if (typeof schema.exclusiveMinimum === 'number') {
150+
schema.minimum = schema.exclusiveMinimum;
151+
schema.exclusiveMinimum = true;
152+
}
153+
return schema;
154+
}
155+
143156
module.exports = convert;

test/exclusiveMinMax.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
const convert = require('../');
4+
const should = require('should');
5+
6+
it('exclusiveMinMax', () => {
7+
const schema = {
8+
$schema: 'http://json-schema.org/draft-04/schema#',
9+
type: 'integer',
10+
exclusiveMaximum: 10,
11+
exclusiveMinimum: 0
12+
};
13+
14+
const result = convert(schema);
15+
16+
const expected = {
17+
type: 'integer',
18+
maximum: 10,
19+
exclusiveMaximum: true,
20+
minimum: 0,
21+
exclusiveMinimum: true
22+
};
23+
24+
should(result).deepEqual(expected, 'converted');
25+
});

0 commit comments

Comments
 (0)