mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-10-31 15:57:30 +03:00 
			
		
		
		
	fix: external ref in schema definition (#1894)
This commit is contained in:
		
							parent
							
								
									60f012d760
								
							
						
					
					
						commit
						57cdd9f6da
					
				|  | @ -191,6 +191,9 @@ export class OpenAPIParser { | ||||||
|     const { $ref, ...rest } = ref; |     const { $ref, ...rest } = ref; | ||||||
|     const keys = Object.keys(rest); |     const keys = Object.keys(rest); | ||||||
|     if (keys.length === 0) { |     if (keys.length === 0) { | ||||||
|  |       if (this.isRef(resolved)) { | ||||||
|  |         return this.shallowDeref(resolved); | ||||||
|  |       } | ||||||
|       return resolved; |       return resolved; | ||||||
|     } |     } | ||||||
|     if ( |     if ( | ||||||
|  |  | ||||||
|  | @ -26,5 +26,16 @@ describe('Models', () => { | ||||||
| 
 | 
 | ||||||
|       expect(parser.shallowDeref(schemaOrRef)).toMatchSnapshot(); |       expect(parser.shallowDeref(schemaOrRef)).toMatchSnapshot(); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     test('should correct resolve double $ref if no need sibling', () => { | ||||||
|  |       // eslint-disable-next-line @typescript-eslint/no-var-requires
 | ||||||
|  |       const spec = require('./fixtures/3.1/schemaDefinition.json'); | ||||||
|  |       parser = new OpenAPIParser(spec, undefined, opts); | ||||||
|  |       const schemaOrRef: Referenced<OpenAPIParameter> = { | ||||||
|  |         $ref: '#/components/schemas/Parent', | ||||||
|  |       }; | ||||||
|  | 
 | ||||||
|  |       expect(parser.deref(schemaOrRef, false, true)).toMatchSnapshot(); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,16 @@ | ||||||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | // Jest Snapshot v1, https://goo.gl/fbAQLP | ||||||
| 
 | 
 | ||||||
|  | exports[`Models Schema should correct resolve double $ref if no need sibling 1`] = ` | ||||||
|  | Object { | ||||||
|  |   "properties": Object { | ||||||
|  |     "test": Object { | ||||||
|  |       "type": "string", | ||||||
|  |     }, | ||||||
|  |   }, | ||||||
|  |   "type": "object", | ||||||
|  | } | ||||||
|  | `; | ||||||
|  | 
 | ||||||
| exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | exports[`Models Schema should hoist oneOfs when mergin allOf 1`] = ` | ||||||
| Object { | Object { | ||||||
|   "oneOf": Array [ |   "oneOf": Array [ | ||||||
|  |  | ||||||
							
								
								
									
										54
									
								
								src/services/__tests__/fixtures/3.1/schemaDefinition.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								src/services/__tests__/fixtures/3.1/schemaDefinition.json
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,54 @@ | ||||||
|  | { | ||||||
|  |   "openapi": "3.1.0", | ||||||
|  |   "info": { | ||||||
|  |     "title": "Schema definition double $ref", | ||||||
|  |     "version": "1.0.0" | ||||||
|  |   }, | ||||||
|  |   "servers": [ | ||||||
|  |     { | ||||||
|  |       "url": "example.com" | ||||||
|  |     } | ||||||
|  |   ], | ||||||
|  |   "tags": [ | ||||||
|  |     { | ||||||
|  |       "name": "test", | ||||||
|  |       "x-displayName": "The test Model", | ||||||
|  |       "description": "<SchemaDefinition schemaRef=\"#/components/schemas/Parent\" />\n" | ||||||
|  |     } | ||||||
|  |   ], | ||||||
|  |   "paths": { | ||||||
|  |     "/newPath": { | ||||||
|  |       "post": { | ||||||
|  |         "requestBody": { | ||||||
|  |           "content": { | ||||||
|  |             "application/json": { | ||||||
|  |               "schema": { | ||||||
|  |                 "$ref": "#/components/schemas/Child" | ||||||
|  |               } | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  |         }, | ||||||
|  |         "responses": { | ||||||
|  |           "200": { | ||||||
|  |             "description": "all ok" | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "components": { | ||||||
|  |     "schemas": { | ||||||
|  |       "Parent": { | ||||||
|  |         "$ref": "#/components/schemas/Child" | ||||||
|  |       }, | ||||||
|  |       "Child": { | ||||||
|  |         "type": "object", | ||||||
|  |         "properties": { | ||||||
|  |           "test": { | ||||||
|  |             "type": "string" | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | @ -40,5 +40,13 @@ describe('Models', () => { | ||||||
|       expect(schema.oneOf).toHaveLength(2); |       expect(schema.oneOf).toHaveLength(2); | ||||||
|       expect(schema.displayType).toBe('(Array of strings or numbers) or string'); |       expect(schema.displayType).toBe('(Array of strings or numbers) or string'); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     test('schemaDefinition should resolve double ref', () => { | ||||||
|  |       const spec = require('../fixtures/3.1/schemaDefinition.json'); | ||||||
|  |       parser = new OpenAPIParser(spec, undefined, opts); | ||||||
|  |       const schema = new SchemaModel(parser, spec.components.schemas.Parent, '', opts); | ||||||
|  |       expect(schema.fields).toHaveLength(1); | ||||||
|  |       expect(schema.pointer).toBe('#/components/schemas/Child'); | ||||||
|  |     }); | ||||||
|   }); |   }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user