@@ -8,6 +8,11 @@ const initialState = {
8
8
required : [ ] ,
9
9
}
10
10
11
+ const isFluentSchema = obj => typeof obj . title === 'function'
12
+
13
+ const hasCombiningKeywords = attributes =>
14
+ attributes . anyOf || attributes . anyOf || attributes . anyOf || attributes . not
15
+
11
16
const last = arr => {
12
17
const [ prop ] = [ ...arr ] . reverse ( )
13
18
return prop
@@ -64,20 +69,13 @@ const FluentSchema = (schema = initialState) => ({
64
69
} ,
65
70
66
71
definition : ( name , props = { } ) =>
67
- FluentSchema ( { ...schema } ) . prop ( name , props , true ) ,
72
+ FluentSchema ( { ...schema } ) . prop ( name , { ... props , def : true } ) ,
68
73
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
74
77
const {
75
- type = attributes . anyOf ||
76
- attributes . anyOf ||
77
- attributes . anyOf ||
78
- attributes . not
79
- ? undefined
80
- : 'string' ,
78
+ type = hasCombiningKeywords ( attributes ) ? undefined : 'string' ,
81
79
// TODO LS $id should be prefixed with the parent
82
80
$id = `#${ target } /${ name } ` ,
83
81
$ref,
0 commit comments