@@ -178,10 +178,17 @@ function searchForExampleByPointer(pointer, examples = []) {
178
178
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md
179
179
* @param {Object } data
180
180
* @param {Object[] } prevSchemas
181
- * @param {string } currentLocation
181
+ * @param {String } currentLocation
182
182
* @param {Object } globalDefaults
183
+ * @param {Boolean } isPolymorphicAllOfChild
183
184
*/
184
- function constructSchema ( data , prevSchemas = [ ] , currentLocation = '' , globalDefaults ) {
185
+ function constructSchema (
186
+ data ,
187
+ prevSchemas = [ ] ,
188
+ currentLocation = '' ,
189
+ globalDefaults ,
190
+ isPolymorphicAllOfChild = false
191
+ ) {
185
192
const schema = { ...data } ;
186
193
187
194
// If this schema contains a `$ref`, it's circular and we shouldn't try to resolve it. Just return and move along.
@@ -197,6 +204,15 @@ function constructSchema(data, prevSchemas = [], currentLocation = '', globalDef
197
204
schema . type = 'object' ;
198
205
} else if ( 'items' in schema ) {
199
206
schema . type = 'array' ;
207
+ } else if ( isPolymorphicAllOfChild ) {
208
+ // If this schema is immediate child of a polymorphic schema and is neither an array or an object, we should
209
+ // leave it alone. Cases like this are common where somebody might use `allOf` in order to dynamically add a
210
+ // `description` onto another schema, like such:
211
+ //
212
+ // allOf: [
213
+ // { type: 'array', items: { type: 'string' },
214
+ // { description: 'This is the description for the `array`.' }
215
+ // ]
200
216
} else {
201
217
// If we're processing a schema that has no types, no refs, and is just a lone schema, we should treat it at the
202
218
// bare minimum as a simple string so we make an attempt to generate valid JSON Schema.
@@ -330,7 +346,13 @@ function constructSchema(data, prevSchemas = [], currentLocation = '', globalDef
330
346
[ 'allOf' , 'anyOf' , 'oneOf' ] . forEach ( polyType => {
331
347
if ( polyType in schema && Array . isArray ( schema [ polyType ] ) ) {
332
348
schema [ polyType ] . forEach ( ( item , idx ) => {
333
- schema [ polyType ] [ idx ] = constructSchema ( item , prevSchemas , `${ currentLocation } /${ idx } ` , globalDefaults ) ;
349
+ schema [ polyType ] [ idx ] = constructSchema (
350
+ item ,
351
+ prevSchemas ,
352
+ `${ currentLocation } /${ idx } ` ,
353
+ globalDefaults ,
354
+ polyType === 'allOf'
355
+ ) ;
334
356
} ) ;
335
357
}
336
358
} ) ;
0 commit comments