@@ -59,10 +59,16 @@ const FluentSchema = (
59
59
} ,
60
60
definition : ( name , props = { } ) =>
61
61
FluentSchema ( { ...schema } ) . prop ( name , props , true ) ,
62
+
63
+ //TODO LS move 'def' in the props
62
64
prop : ( name , props = { } , def = false ) => {
63
65
const target = def ? 'definitions' : 'properties'
66
+ const attributes =
67
+ typeof props . title === 'function' ? props . valueOf ( ) : props
64
68
const {
65
- type = 'string' ,
69
+ type = attributes . anyOf || attributes . anyOf || attributes . anyOf
70
+ ? undefined
71
+ : 'string' ,
66
72
// TODO LS $id should be prefixed with the parent
67
73
$id = `#${ target } /${ name } ` ,
68
74
$ref,
@@ -71,7 +77,10 @@ const FluentSchema = (
71
77
defaults,
72
78
properties,
73
79
required,
74
- } = typeof props . title === 'function' ? props . valueOf ( ) : props
80
+ anyOf,
81
+ allOf,
82
+ oneOf,
83
+ } = attributes
75
84
76
85
return FluentSchema ( {
77
86
...schema ,
@@ -87,12 +96,29 @@ const FluentSchema = (
87
96
$id ? { $id } : undefined ,
88
97
description ? { description } : undefined ,
89
98
properties ? { properties } : undefined ,
90
- required ? { required } : undefined
99
+ required ? { required } : undefined ,
100
+ anyOf ? { anyOf } : undefined ,
101
+ oneOf ? { oneOf } : undefined ,
102
+ allOf ? { allOf } : undefined
91
103
) ,
92
104
] ,
93
105
} )
94
106
} ,
95
107
108
+ anyOf : attributes => {
109
+ const currentProp = last ( schema . properties )
110
+ const { name, type, ...props } = currentProp
111
+ const properties = attributes . valueOf ( ) . properties
112
+ const values = Object . entries ( properties ) . reduce ( ( memo , [ key , value ] ) => {
113
+ return [ ...memo , value ]
114
+ } , [ ] )
115
+ const attr = {
116
+ ...props ,
117
+ anyOf : values ,
118
+ }
119
+ return FluentSchema ( { ...schema } ) . prop ( name , attr )
120
+ } ,
121
+
96
122
required : ( ) => {
97
123
const currentProp = last ( schema . properties )
98
124
return FluentSchema ( {
0 commit comments