6
6
getSerializedPropertyType ,
7
7
getSerializedRecursiveType ,
8
8
getSerializedRefType ,
9
+ getSerializedUnionType ,
9
10
intercalateSerializedTypes ,
10
11
SERIALIZED_BOOLEAN_TYPE ,
11
12
SERIALIZED_NUMERIC_TYPE ,
@@ -22,9 +23,10 @@ import { constFalse } from 'fp-ts/lib/function';
22
23
import { includes } from '../../../../utils/array' ;
23
24
import { sequenceEither } from '@devexperts/utils/dist/adt/either.utils' ;
24
25
import { fromString , Ref } from '../../../../utils/ref' ;
25
- import { AllOfSchemaObjectCodec , SchemaObject } from '../../../../schema/3.0/schema-object' ;
26
+ import { AllOfSchemaObjectCodec , OneOfSchemaObjectCodec , SchemaObject } from '../../../../schema/3.0/schema-object' ;
26
27
import { ReferenceObject , ReferenceObjectCodec } from '../../../../schema/3.0/reference-object' ;
27
28
import { traverseNEAEither } from '../../../../utils/either' ;
29
+ import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray' ;
28
30
29
31
type AdditionalProperties = boolean | ReferenceObject | SchemaObject ;
30
32
type AllowedAdditionalProperties = true | ReferenceObject | SchemaObject ;
@@ -41,18 +43,17 @@ export const serializeSchemaObject = (
41
43
const serializeSchemaObjectWithRecursion = ( from : Ref , shouldTrackRecursion : boolean , name ?: string ) => (
42
44
schemaObject : SchemaObject ,
43
45
) : Either < Error , SerializedType > => {
46
+ if ( OneOfSchemaObjectCodec . is ( schemaObject ) ) {
47
+ return pipe (
48
+ serializeChildren ( from , schemaObject . oneOf ) ,
49
+ either . map ( getSerializedUnionType ) ,
50
+ either . map ( getSerializedRecursiveType ( from , shouldTrackRecursion ) ) ,
51
+ ) ;
52
+ }
53
+
44
54
if ( AllOfSchemaObjectCodec . is ( schemaObject ) ) {
45
55
return pipe (
46
- traverseNEAEither ( schemaObject . allOf , item => {
47
- if ( ReferenceObjectCodec . is ( item ) ) {
48
- return pipe (
49
- fromString ( item . $ref ) ,
50
- either . map ( getSerializedRefType ( from ) ) ,
51
- ) ;
52
- } else {
53
- return serializeSchemaObjectWithRecursion ( from , false ) ( item ) ;
54
- }
55
- } ) ,
56
+ serializeChildren ( from , schemaObject . allOf ) ,
56
57
either . map ( getSerializedIntersectionType ) ,
57
58
either . map ( getSerializedRecursiveType ( from , shouldTrackRecursion ) ) ,
58
59
) ;
@@ -166,3 +167,16 @@ const serializeSchemaObjectWithRecursion = (from: Ref, shouldTrackRecursion: boo
166
167
}
167
168
}
168
169
} ;
170
+
171
+ const serializeChildren = (
172
+ from : Ref ,
173
+ children : NonEmptyArray < ReferenceObject | SchemaObject > ,
174
+ ) : Either < Error , NonEmptyArray < SerializedType > > =>
175
+ traverseNEAEither ( children , item =>
176
+ ReferenceObjectCodec . is ( item )
177
+ ? pipe (
178
+ fromString ( item . $ref ) ,
179
+ either . map ( getSerializedRefType ( from ) ) ,
180
+ )
181
+ : serializeSchemaObjectWithRecursion ( from , false ) ( item ) ,
182
+ ) ;
0 commit comments