mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-10-31 15:57:30 +03:00 
			
		
		
		
	fix: show siblings schema with oneOf (#2576)
This commit is contained in:
		
							parent
							
								
									a7607eafdd
								
							
						
					
					
						commit
						60d131b0a9
					
				|  | @ -364,14 +364,18 @@ export class OpenAPIParser { | ||||||
| 
 | 
 | ||||||
|     const allOf = schema.allOf; |     const allOf = schema.allOf; | ||||||
|     for (let i = 0; i < allOf.length; i++) { |     for (let i = 0; i < allOf.length; i++) { | ||||||
|       const sub = allOf[i]; |       const { oneOf, ...sub } = allOf[i]; | ||||||
|       if (Array.isArray(sub.oneOf)) { |       if (!oneOf) { | ||||||
|  |         continue; | ||||||
|  |       } | ||||||
|  |       if (Array.isArray(oneOf)) { | ||||||
|         const beforeAllOf = allOf.slice(0, i); |         const beforeAllOf = allOf.slice(0, i); | ||||||
|         const afterAllOf = allOf.slice(i + 1); |         const afterAllOf = allOf.slice(i + 1); | ||||||
|  |         const siblingValues = Object.keys(sub).length > 0 ? [sub] : []; | ||||||
|         return { |         return { | ||||||
|           oneOf: sub.oneOf.map((part: OpenAPISchema) => { |           oneOf: oneOf.map((part: OpenAPISchema) => { | ||||||
|             return { |             return { | ||||||
|               allOf: [...beforeAllOf, part, ...afterAllOf], |               allOf: [...beforeAllOf, ...siblingValues, part, ...afterAllOf], | ||||||
|               'x-refsStack': refsStack, |               'x-refsStack': refsStack, | ||||||
|             }; |             }; | ||||||
|           }), |           }), | ||||||
|  |  | ||||||
|  | @ -21,6 +21,14 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | ||||||
|   "oneOf": [ |   "oneOf": [ | ||||||
|     { |     { | ||||||
|       "allOf": [ |       "allOf": [ | ||||||
|  |         { | ||||||
|  |           "properties": { | ||||||
|  |             "id": { | ||||||
|  |               "description": "The user's ID", | ||||||
|  |               "type": "integer", | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|         { |         { | ||||||
|           "properties": { |           "properties": { | ||||||
|             "username": { |             "username": { | ||||||
|  | @ -61,6 +69,14 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | ||||||
|     }, |     }, | ||||||
|     { |     { | ||||||
|       "allOf": [ |       "allOf": [ | ||||||
|  |         { | ||||||
|  |           "properties": { | ||||||
|  |             "id": { | ||||||
|  |               "description": "The user's ID", | ||||||
|  |               "type": "integer", | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|         { |         { | ||||||
|           "properties": { |           "properties": { | ||||||
|             "email": { |             "email": { | ||||||
|  | @ -99,6 +115,55 @@ exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | ||||||
|       ], |       ], | ||||||
|       "x-refsStack": undefined, |       "x-refsStack": undefined, | ||||||
|     }, |     }, | ||||||
|  |     { | ||||||
|  |       "allOf": [ | ||||||
|  |         { | ||||||
|  |           "properties": { | ||||||
|  |             "id": { | ||||||
|  |               "description": "The user's ID", | ||||||
|  |               "type": "integer", | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "properties": { | ||||||
|  |             "id": { | ||||||
|  |               "description": "The user's ID", | ||||||
|  |               "format": "uuid", | ||||||
|  |               "type": "string", | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "properties": { | ||||||
|  |             "extra": { | ||||||
|  |               "type": "string", | ||||||
|  |             }, | ||||||
|  |           }, | ||||||
|  |         }, | ||||||
|  |         { | ||||||
|  |           "oneOf": [ | ||||||
|  |             { | ||||||
|  |               "properties": { | ||||||
|  |                 "password": { | ||||||
|  |                   "description": "The user's password", | ||||||
|  |                   "type": "string", | ||||||
|  |                 }, | ||||||
|  |               }, | ||||||
|  |             }, | ||||||
|  |             { | ||||||
|  |               "properties": { | ||||||
|  |                 "mobile": { | ||||||
|  |                   "description": "The user's mobile", | ||||||
|  |                   "type": "string", | ||||||
|  |                 }, | ||||||
|  |               }, | ||||||
|  |             }, | ||||||
|  |           ], | ||||||
|  |         }, | ||||||
|  |       ], | ||||||
|  |       "x-refsStack": undefined, | ||||||
|  |     }, | ||||||
|   ], |   ], | ||||||
| } | } | ||||||
| `; | `; | ||||||
|  |  | ||||||
|  | @ -9,6 +9,12 @@ | ||||||
|       "test": { |       "test": { | ||||||
|         "allOf": [ |         "allOf": [ | ||||||
|           { |           { | ||||||
|  |             "properties": { | ||||||
|  |               "id": { | ||||||
|  |                 "description": "The user's ID", | ||||||
|  |                 "type": "integer" | ||||||
|  |               } | ||||||
|  |             }, | ||||||
|             "oneOf": [ |             "oneOf": [ | ||||||
|               { |               { | ||||||
|                 "properties": { |                 "properties": { | ||||||
|  | @ -25,6 +31,15 @@ | ||||||
|                     "type": "string" |                     "type": "string" | ||||||
|                   } |                   } | ||||||
|                 } |                 } | ||||||
|  |               }, | ||||||
|  |               { | ||||||
|  |                 "properties": { | ||||||
|  |                   "id": { | ||||||
|  |                     "description": "The user's ID", | ||||||
|  |                     "type": "string", | ||||||
|  |                     "format": "uuid" | ||||||
|  |                   } | ||||||
|  |                 } | ||||||
|               } |               } | ||||||
|             ] |             ] | ||||||
|           }, |           }, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user