Skip to content

Commit c94156e

Browse files
committed
Cleanup prop implementation
1 parent f5ffde4 commit c94156e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/FluentSchema.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const initialState = {
88
required: [],
99
}
1010

11+
const isFluentSchema = obj => typeof obj.title === 'function'
12+
13+
const hasCombiningKeywords = attributes =>
14+
attributes.anyOf || attributes.anyOf || attributes.anyOf || attributes.not
15+
1116
const last = arr => {
1217
const [prop] = [...arr].reverse()
1318
return prop
@@ -64,20 +69,13 @@ const FluentSchema = (schema = initialState) => ({
6469
},
6570

6671
definition: (name, props = {}) =>
67-
FluentSchema({ ...schema }).prop(name, props, true),
72+
FluentSchema({ ...schema }).prop(name, { ...props, def: true }),
6873

69-
//TODO LS move 'def' in the props
70-
prop: (name, props = {}, def = false) => {
71-
const target = def ? 'definitions' : 'properties'
72-
const attributes =
73-
typeof props.title === 'function' ? props.valueOf() : props
74+
prop: (name, props = {}) => {
75+
const target = props.def ? 'definitions' : 'properties'
76+
const attributes = isFluentSchema(props) ? props.valueOf() : props
7477
const {
75-
type = attributes.anyOf ||
76-
attributes.anyOf ||
77-
attributes.anyOf ||
78-
attributes.not
79-
? undefined
80-
: 'string',
78+
type = hasCombiningKeywords(attributes) ? undefined : 'string',
8179
// TODO LS $id should be prefixed with the parent
8280
$id = `#${target}/${name}`,
8381
$ref,

0 commit comments

Comments
 (0)