Skip to content

Commit 58b2095

Browse files
authored
handle enum property when type is not specified (#324)
1 parent f5daf9f commit 58b2095

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ const objectKeywords = [
167167
'properties',
168168
'patternProperties',
169169
'additionalProperties',
170-
'dependencies',
171-
'enum'
170+
'dependencies'
172171
]
173172

174173
const arrayKeywords = [
@@ -1130,10 +1129,6 @@ function nested (laterCode, name, key, location, subKey, isArray) {
11301129
const inferredType = inferTypeByKeyword(schema)
11311130
if (inferredType) {
11321131
schema.type = inferredType
1133-
1134-
if (inferredType === 'object' && schema.enum && !Object.hasOwnProperty.call(schema, 'additionalProperties')) {
1135-
schema.additionalProperties = true
1136-
}
11371132
}
11381133
}
11391134

test/enum.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const build = require('..')
5+
6+
test('use enum without type', (t) => {
7+
t.plan(1)
8+
const stringify = build({
9+
title: 'Example Schema',
10+
type: 'object',
11+
properties: {
12+
order: {
13+
type: 'string',
14+
enum: ['asc', 'desc']
15+
}
16+
}
17+
})
18+
19+
const obj = { order: 'asc' }
20+
t.equal('{"order":"asc"}', stringify(obj))
21+
})
22+
23+
test('use enum without type', (t) => {
24+
t.plan(1)
25+
const stringify = build({
26+
title: 'Example Schema',
27+
type: 'object',
28+
properties: {
29+
order: {
30+
enum: ['asc', 'desc']
31+
}
32+
}
33+
})
34+
35+
const obj = { order: 'asc' }
36+
t.equal('{"order":"asc"}', stringify(obj))
37+
})

0 commit comments

Comments
 (0)