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 08b682e

Browse files
author
Phil Sturgeon
authored
Merge branch 'master' into if-then-else
2 parents 58a9b62 + 974538d commit 08b682e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

‎index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ function convertSchema(schema, path, parent, parentPath) {
3131
schema = convertTypes(schema);
3232
schema = convertDependencies(schema);
3333
schema = rewriteIfThenElse(schema);
34+
schema = rewriteExclusiveMinMax(schema);
3435

3536
if (typeof schema['patternProperties'] === 'object') {
3637
schema = convertPatternProperties(schema);
3738
}
3839

40+
if (schema.type === 'array' && typeof schema.items === 'undefined') {
41+
schema.items = {};
42+
}
43+
3944
return schema;
4045
}
4146

@@ -159,6 +164,18 @@ oneOf: [allOf: [X, Y], allOf: [not: X, Z]]
159164
delete schema.if;
160165
delete schema.then;
161166
delete schema.else;
167+
}
168+
return schema;
169+
}
170+
171+
function rewriteExclusiveMinMax(schema) {
172+
if (typeof schema.exclusiveMaximum === 'number') {
173+
schema.maximum = schema.exclusiveMaximum;
174+
schema.exclusiveMaximum = true;
175+
}
176+
if (typeof schema.exclusiveMinimum === 'number') {
177+
schema.minimum = schema.exclusiveMinimum;
178+
schema.exclusiveMinimum = true;
162179
}
163180
return schema;
164181
}

‎test/array-items.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
const convert = require('../');
4+
const should = require('should');
5+
6+
it('array-items', () => {
7+
const schema = {
8+
$schema: 'http://json-schema.org/draft-04/schema#',
9+
type: 'array',
10+
};
11+
12+
const result = convert(schema);
13+
14+
const expected = {
15+
type: 'array',
16+
items: {
17+
}
18+
};
19+
20+
should(result).deepEqual(expected, 'converted');
21+
});

‎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 によって変換されたページ (->オリジナル) /