@@ -182,8 +182,65 @@ test('missing id in root schema', t => {
182182
183183 const resolver = RefResolver ( )
184184 const out = resolver . resolve ( schema , opts )
185- save ( out )
186185 t . deepEquals ( schema , out , 'the output is the same input modified' )
187186 t . ok ( out . definitions , 'definitions has been added' )
188187 t . deepEquals ( Object . values ( out . definitions ) , opts . externalSchemas , 'external schema has been added to definitions' )
189188} )
189+
190+ test ( 'absolute $ref' , t => {
191+ t . plan ( 2 )
192+ const schema = { $ref : 'http://example.com/#/definitions/idParam' }
193+
194+ const absSchemaId = {
195+ $id : 'http://example.com/' ,
196+ definitions : {
197+ uuid : {
198+ type : 'string' ,
199+ pattern : '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
200+ } ,
201+ idParam : {
202+ type : 'object' ,
203+ required : [ 'id' ] ,
204+ properties : {
205+ id : { $ref : '#/definitions/uuid' }
206+ } ,
207+ additionalProperties : false
208+ }
209+ }
210+ }
211+
212+ const externalSchemas = [ absSchemaId ]
213+
214+ const resolver = RefResolver ( { clone : true , applicationUri : 'todo.com' , externalSchemas } )
215+ const out = resolver . resolve ( schema )
216+
217+ t . notEqual ( out . $ref , 'http://example.com/#/definitions/idParam' )
218+ t . deepEquals ( resolver . definitions ( ) , {
219+ definitions : {
220+ 'def-0' : absSchemaId
221+ }
222+ } )
223+ } )
224+
225+ test ( 'absolute $ref #2' , t => {
226+ t . plan ( 2 )
227+ const schema = factory ( 'absoluteId-absoluteRef' )
228+
229+ const absSchemaId = {
230+ $id : 'http://other-site.com/relativeAddress' ,
231+ type : 'object' ,
232+ properties : {
233+ uuid : {
234+ type : 'string' ,
235+ pattern : '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
236+ }
237+ }
238+ }
239+
240+ const externalSchemas = [ absSchemaId ]
241+
242+ const resolver = RefResolver ( { clone : true } )
243+ const out = resolver . resolve ( schema , { externalSchemas } )
244+ t . equal ( out . properties . address . $ref , '#/definitions/def-0' )
245+ t . equal ( out . properties . houses . items . $ref , '#/definitions/def-0' )
246+ } )
0 commit comments