Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 974538d

Browse files
author
Phil Sturgeon
authored
Merge pull request #16 from MikeRalphson/exclusives
rewrite exclusiveMinimum/exclusiveMaximum
2 parents 142ca43 + 27e0cfe commit 974538d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎index.js

Lines changed: 13 additions & 0 deletions
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);
@@ -144,4 +145,16 @@ function convertPatternProperties(schema) {
144145
return schema;
145146
}
146147

148+
function rewriteExclusiveMinMax(schema) {
149+
if (typeof schema.exclusiveMaximum === 'number') {
150+
schema.maximum = schema.exclusiveMaximum;
151+
schema.exclusiveMaximum = true;
152+
}
153+
if (typeof schema.exclusiveMinimum === 'number') {
154+
schema.minimum = schema.exclusiveMinimum;
155+
schema.exclusiveMinimum = true;
156+
}
157+
return schema;
158+
}
159+
147160
module.exports = convert;

‎test/exclusiveMinMax.test.js

Lines changed: 25 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /