Skip to content

Commit ed38775

Browse files
author
Phil Sturgeon
authored
Merge pull request #5 from noc7c9/master
Fix issue with falsy const values not triggering the rewrite
2 parents 35f865a + 71bef7b commit ed38775

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function convertExamples(schema) {
170170
}
171171

172172
function rewriteConst(schema) {
173-
if (schema.const) {
173+
if (Object.hasOwnProperty.call(schema, 'const')) {
174174
schema.enum = [ schema.const ];
175175
delete schema.const;
176176
}

test/const.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ it('const', async () => {
1919

2020
should(result).deepEqual(expected, 'converted');
2121
});
22+
23+
it('falsy const', async () => {
24+
const schema = {
25+
$schema: 'http://json-schema.org/draft-04/schema#',
26+
type: 'boolean',
27+
const: false
28+
};
29+
30+
const result = await convert(schema);
31+
32+
const expected = {
33+
type: 'boolean',
34+
enum: [ false ]
35+
};
36+
37+
should(result).deepEqual(expected, 'converted');
38+
});

0 commit comments

Comments
 (0)