@@ -21,6 +21,11 @@ type CombinedData = {
21
21
isEnum : boolean [ ] ;
22
22
types : string [ ] ;
23
23
hasReadonlyProps : boolean ;
24
+ /**
25
+ * List of all properties in all subschemas
26
+ * - used to add missing properties in subschemas to avoid TS error described in @see https://github.com/anymaniax/orval/issues/935
27
+ */
28
+ allProperties : string [ ] ;
24
29
} ;
25
30
26
31
type Separator = 'allOf' | 'anyOf' | 'oneOf' ;
@@ -48,13 +53,37 @@ const combineValues = ({
48
53
} `;
49
54
}
50
55
56
+ let values = resolvedData . values ;
57
+ const hasObjectSubschemas = resolvedData . allProperties . length ;
58
+ if ( hasObjectSubschemas ) {
59
+ values = [ ] ; // the list of values will be rebuilt to add missing properties (if exist) in subschemas
60
+ for ( let i = 0 ; i < resolvedData . values . length ; i += 1 ) {
61
+ const subSchema = resolvedData . originalSchema [ i ] ;
62
+ if ( subSchema ?. type !== 'object' ) {
63
+ values . push ( resolvedData . values [ i ] ) ;
64
+ continue ;
65
+ }
66
+
67
+ const missingProperties = resolvedData . allProperties . filter (
68
+ ( p ) => ! Object . keys ( subSchema . properties ! ) . includes ( p ) ,
69
+ ) ;
70
+ values . push (
71
+ `${ resolvedData . values [ i ] } ${
72
+ missingProperties . length
73
+ ? ` & {${ missingProperties . map ( ( p ) => `${ p } ?: never` ) . join ( '; ' ) } }`
74
+ : ''
75
+ } `,
76
+ ) ;
77
+ }
78
+ }
79
+
51
80
if ( resolvedValue ) {
52
- return `(${ resolvedData . values . join ( ` & ${ resolvedValue . value } ) | (` ) } & ${
81
+ return `(${ values . join ( ` & ${ resolvedValue . value } ) | (` ) } & ${
53
82
resolvedValue . value
54
83
} )`;
55
84
}
56
85
57
- return resolvedData . values . join ( ' | ' ) ;
86
+ return values . join ( ' | ' ) ;
58
87
} ;
59
88
60
89
export const combineSchemas = ( {
@@ -95,6 +124,12 @@ export const combineSchemas = ({
95
124
acc . originalSchema . push ( resolvedValue . originalSchema ) ;
96
125
acc . hasReadonlyProps ||= resolvedValue . hasReadonlyProps ;
97
126
127
+ if ( resolvedValue . type === 'object' ) {
128
+ acc . allProperties . push (
129
+ ...Object . keys ( resolvedValue . originalSchema . properties ! ) ,
130
+ ) ;
131
+ }
132
+
98
133
return acc ;
99
134
} ,
100
135
{
@@ -105,6 +140,7 @@ export const combineSchemas = ({
105
140
isRef : [ ] ,
106
141
types : [ ] ,
107
142
originalSchema : [ ] ,
143
+ allProperties : [ ] ,
108
144
hasReadonlyProps : false ,
109
145
example : schema . example ,
110
146
examples : resolveExampleRefs ( schema . examples , context ) ,
0 commit comments