@@ -106,18 +106,7 @@ export async function getBodyParams(schema, topLevel = false) {
106
106
if ( param . items . oneOf . every ( ( object ) => object . type === 'object' ) ) {
107
107
paramType . splice ( paramType . indexOf ( 'array' ) , 1 , `array of objects` )
108
108
param . oneOfObject = true
109
-
110
- for ( const oneOfParam of param . items . oneOf ) {
111
- const objParam = {
112
- type : 'object' ,
113
- name : oneOfParam . title ,
114
- description : await renderContent ( oneOfParam . description ) ,
115
- isRequired : oneOfParam . required ,
116
- childParamsGroups : [ ] ,
117
- }
118
- objParam . childParamsGroups . push ( ...( await getBodyParams ( oneOfParam , false ) ) )
119
- childParamsGroups . push ( objParam )
120
- }
109
+ childParamsGroups . push ( ...( await getOneOfChildParams ( param . items ) ) )
121
110
}
122
111
} else {
123
112
const arrayType = param . items . type
@@ -129,7 +118,14 @@ export async function getBodyParams(schema, topLevel = false) {
129
118
}
130
119
}
131
120
} else if ( paramType && paramType . includes ( 'object' ) ) {
132
- childParamsGroups . push ( ...( await getBodyParams ( param , false ) ) )
121
+ if ( param && param . oneOf ) {
122
+ if ( param . oneOf . every ( ( object ) => object . type === 'object' ) ) {
123
+ param . oneOfObject = true
124
+ childParamsGroups . push ( ...( await getOneOfChildParams ( param ) ) )
125
+ }
126
+ } else {
127
+ childParamsGroups . push ( ...( await getBodyParams ( param , false ) ) )
128
+ }
133
129
} else if ( param && param . oneOf ) {
134
130
// get concatenated description and type
135
131
const descriptions = [ ]
@@ -150,6 +146,8 @@ export async function getBodyParams(schema, topLevel = false) {
150
146
descriptions . push ( { type : childParam . type , description : childParam . description } )
151
147
}
152
148
}
149
+ } else {
150
+ descriptions . push ( { type : param . type , description : param . description } )
153
151
}
154
152
}
155
153
// Occasionally, there is no parent description and the description
@@ -205,7 +203,7 @@ async function getTransformedParam(param, paramType, props) {
205
203
if ( required && required . includes ( paramKey ) ) {
206
204
paramDecorated . isRequired = true
207
205
}
208
- if ( childParamsGroups && childParamsGroups . length > 0 ) {
206
+ if ( childParamsGroups && childParamsGroups . length > 0 && ! param . oneOfObject ) {
209
207
// Since the allOf properties can have multiple duplicate properties we want to get rid of the duplicates with the same name, but keep the
210
208
// the one that has isRequired set to true.
211
209
const mergedChildParamsGroups = Array . from (
@@ -221,6 +219,8 @@ async function getTransformedParam(param, paramType, props) {
221
219
)
222
220
223
221
paramDecorated . childParamsGroups = mergedChildParamsGroups
222
+ } else if ( childParamsGroups . length > 0 ) {
223
+ paramDecorated . childParamsGroups = childParamsGroups
224
224
}
225
225
if ( param . enum ) {
226
226
paramDecorated . enum = param . enum
@@ -236,3 +236,19 @@ async function getTransformedParam(param, paramType, props) {
236
236
}
237
237
return paramDecorated
238
238
}
239
+
240
+ async function getOneOfChildParams ( param ) {
241
+ const childParamsGroups = [ ]
242
+ for ( const oneOfParam of param . oneOf ) {
243
+ const objParam = {
244
+ type : 'object' ,
245
+ name : oneOfParam . title ,
246
+ description : await renderContent ( oneOfParam . description ) ,
247
+ isRequired : oneOfParam . required ,
248
+ childParamsGroups : [ ] ,
249
+ }
250
+ objParam . childParamsGroups . push ( ...( await getBodyParams ( oneOfParam , false ) ) )
251
+ childParamsGroups . push ( objParam )
252
+ }
253
+ return childParamsGroups
254
+ }
0 commit comments