@@ -178,10 +178,17 @@ function searchForExampleByPointer(pointer, examples = []) {
178178 * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md
179179 * @param {Object } data
180180 * @param {Object[] } prevSchemas
181- * @param {string } currentLocation
181+ * @param {String } currentLocation
182182 * @param {Object } globalDefaults
183+ * @param {Boolean } isPolymorphicAllOfChild
183184 */
184- function constructSchema ( data , prevSchemas = [ ] , currentLocation = '' , globalDefaults ) {
185+ function constructSchema (
186+ data ,
187+ prevSchemas = [ ] ,
188+ currentLocation = '' ,
189+ globalDefaults ,
190+ isPolymorphicAllOfChild = false
191+ ) {
185192 const schema = { ...data } ;
186193
187194 // 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
197204 schema . type = 'object' ;
198205 } else if ( 'items' in schema ) {
199206 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+ // ]
200216 } else {
201217 // If we're processing a schema that has no types, no refs, and is just a lone schema, we should treat it at the
202218 // 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
330346 [ 'allOf' , 'anyOf' , 'oneOf' ] . forEach ( polyType => {
331347 if ( polyType in schema && Array . isArray ( schema [ polyType ] ) ) {
332348 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+ ) ;
334356 } ) ;
335357 }
336358 } ) ;
0 commit comments