@@ -63,13 +63,31 @@ export const toJsonSchema = (
63
63
) ,
64
64
} ;
65
65
}
66
- if ( type . _tag === 'IntersectionType' ) {
66
+ if ( type . _tag === 'IntersectionType' && ! alwaysIncludeRequired ) {
67
67
return {
68
68
allOf : type . types . map ( ( t : any ) =>
69
69
toJsonSchema ( t , strict , alwaysIncludeRequired ) ,
70
70
) ,
71
71
} ;
72
72
}
73
+ if ( type . _tag === 'IntersectionType' && alwaysIncludeRequired ) {
74
+ const results = type . types . map ( ( t : any ) =>
75
+ toJsonSchema ( t , strict , alwaysIncludeRequired ) ,
76
+ ) ;
77
+ if ( ! results . every ( ( r : any ) => r . type === 'object' ) ) {
78
+ throw new Error ( 'InterfaceType must have all children as type=object' ) ;
79
+ }
80
+ return {
81
+ type : 'object' ,
82
+ required : results . map ( ( r : any ) => r . required ) . flat ( ) ,
83
+ properties : results . reduce (
84
+ ( acc : any , r : any ) => ( { ...acc , ...r . properties } ) ,
85
+ { } as any ,
86
+ ) ,
87
+ ...( strict ? { additionalProperties : false } : { } ) ,
88
+ } ;
89
+ }
90
+
73
91
if ( type . _tag === 'InterfaceType' ) {
74
92
return {
75
93
type : 'object' ,
@@ -138,7 +156,7 @@ export const toJsonSchema = (
138
156
} ;
139
157
}
140
158
// could add more here for DateFromISOString, etc. etc.
141
- return unhandledType ( type ) ;
159
+ return unhandledType ( type as never ) ;
142
160
} ;
143
161
144
162
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unused-vars
0 commit comments