@@ -4,7 +4,7 @@ import { toValue } from '@swagger-api/apidom-core';
4
4
import { isSchemaElement , mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1' ;
5
5
import { evaluate } from '@swagger-api/apidom-json-pointer' ;
6
6
7
- import { dereference } from '../../../../../src' ;
7
+ import { dereference , parse , Reference , ReferenceSet } from '../../../../../src' ;
8
8
import {
9
9
DereferenceError ,
10
10
MaximumDereferenceDepthError ,
@@ -493,6 +493,29 @@ describe('dereference', function () {
493
493
} ) ;
494
494
} ) ;
495
495
496
+ context ( 'given Schema Objects with $ref keyword containing URL path override' , function ( ) {
497
+ const fixturePath = path . join ( rootFixturePath , '$ref-url-path-override' ) ;
498
+
499
+ specify ( 'should dereference' , async function ( ) {
500
+ const rootFilePath = path . join ( fixturePath , 'root.json' ) ;
501
+ const parseResult = await parse ( rootFilePath , {
502
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
503
+ } ) ;
504
+ const uri = 'https://example.com/' ;
505
+ const reference = Reference ( { uri, value : parseResult } ) ;
506
+ const refSet = ReferenceSet ( { refs : [ reference ] } ) ;
507
+
508
+ const actual = await dereference ( uri , {
509
+ dereference : { refSet } ,
510
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
511
+ } ) ;
512
+
513
+ const expected = loadJsonFile ( path . join ( fixturePath , 'dereferenced.json' ) ) ;
514
+
515
+ assert . deepEqual ( toValue ( actual ) , expected ) ;
516
+ } ) ;
517
+ } ) ;
518
+
496
519
context ( 'given Schema Objects with $ref keyword containing resolvable URL' , function ( ) {
497
520
const fixturePath = path . join ( rootFixturePath , '$ref-url-resolvable' ) ;
498
521
@@ -612,6 +635,32 @@ describe('dereference', function () {
612
635
} ,
613
636
) ;
614
637
638
+ context (
639
+ 'given Schema Objects with $anchor keyword after $id pointing to internal schema' ,
640
+ function ( ) {
641
+ const fixturePath = path . join ( rootFixturePath , '$anchor-internal-no-embedding' ) ;
642
+
643
+ specify ( 'should dereference' , async function ( ) {
644
+ const rootFilePath = path . join ( fixturePath , 'root.json' ) ;
645
+ const parseResult = await parse ( rootFilePath , {
646
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
647
+ } ) ;
648
+ const uri = 'https://example.com/' ;
649
+ const reference = Reference ( { uri, value : parseResult } ) ;
650
+ const refSet = ReferenceSet ( { refs : [ reference ] } ) ;
651
+
652
+ const actual = await dereference ( uri , {
653
+ dereference : { refSet } ,
654
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
655
+ } ) ;
656
+
657
+ const expected = loadJsonFile ( path . join ( fixturePath , 'dereferenced.json' ) ) ;
658
+
659
+ assert . deepEqual ( toValue ( actual ) , expected ) ;
660
+ } ) ;
661
+ } ,
662
+ ) ;
663
+
615
664
context (
616
665
'given Schema Objects with $anchor keyword pointing to external schema' ,
617
666
function ( ) {
0 commit comments