You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					49 lines
				
				909 B
			
		
		
			
		
	
	
					49 lines
				
				909 B
			| 
											3 years ago
										 | 'use strict' | ||
|  | 
 | ||
|  | const t = require('tap') | ||
|  | const build = require('..') | ||
|  | 
 | ||
|  | t.test('nested ref requires ajv', async t => { | ||
|  |   const schemaA = { | ||
|  |     $id: 'urn:schema:a', | ||
|  |     definitions: { | ||
|  |       foo: { anyOf: [{ type: 'string' }, { type: 'null' }] } | ||
|  |     } | ||
|  |   } | ||
|  | 
 | ||
|  |   const schemaB = { | ||
|  |     $id: 'urn:schema:b', | ||
|  |     type: 'object', | ||
|  |     properties: { | ||
|  |       results: { | ||
|  |         type: 'object', | ||
|  |         properties: { | ||
|  |           items: { | ||
|  |             type: 'object', | ||
|  |             properties: { | ||
|  |               bar: { | ||
|  |                 type: 'array', | ||
|  |                 items: { $ref: 'urn:schema:a#/definitions/foo' } | ||
|  |               } | ||
|  |             } | ||
|  |           } | ||
|  |         } | ||
|  |       } | ||
|  |     } | ||
|  |   } | ||
|  | 
 | ||
|  |   const stringify = build(schemaB, { | ||
|  |     schema: { | ||
|  |       [schemaA.$id]: schemaA | ||
|  |     } | ||
|  |   }) | ||
|  |   const result = stringify({ | ||
|  |     results: { | ||
|  |       items: { | ||
|  |         bar: ['baz'] | ||
|  |       } | ||
|  |     } | ||
|  |   }) | ||
|  |   t.same(result, '{"results":{"items":{"bar":["baz"]}}}') | ||
|  | }) |