@@ -13,41 +13,85 @@ describe('dereference', function () {
13
13
context ( 'strategies' , function ( ) {
14
14
context ( 'openapi-3-1' , function ( ) {
15
15
context ( 'Path Item Object' , function ( ) {
16
- context ( 'given single PathItemElement passed to dereferenceApiDOM' , function ( ) {
17
- const fixturePath = path . join ( __dirname , 'fixtures' , 'external-only' , 'root.json' ) ;
16
+ context (
17
+ 'given single PathItemElement passed to dereferenceApiDOM with internal references' ,
18
+ function ( ) {
19
+ const fixturePath = path . join ( __dirname , 'fixtures' , 'internal-only' , 'root.json' ) ;
18
20
19
- specify ( 'should dereference' , async function ( ) {
20
- const parseResult = await parse ( fixturePath , {
21
- parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
22
- } ) ;
23
- const pathItemElement = evaluate (
24
- compile ( [ 'paths' , '/path1' ] ) ,
25
- parseResult . api as OpenApi3_1Element ,
26
- ) ;
27
- const dereferenced = await dereferenceApiDOM ( pathItemElement , {
28
- parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
29
- resolve : { baseURI : fixturePath } ,
21
+ specify ( 'should dereference' , async function ( ) {
22
+ const parseResult = await parse ( fixturePath , {
23
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
24
+ } ) ;
25
+ const jsonPointer = compile ( [ 'paths' , '/path1' ] ) ;
26
+ const pathItemElement = evaluate ( jsonPointer , parseResult . api as OpenApi3_1Element ) ;
27
+ const dereferenced = await dereferenceApiDOM ( pathItemElement , {
28
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
29
+ resolve : { baseURI : `${ fixturePath } #${ jsonPointer } ` } ,
30
+ } ) ;
31
+
32
+ assert . isTrue ( isPathItemElement ( dereferenced ) ) ;
30
33
} ) ;
31
34
32
- assert . isTrue ( isPathItemElement ( dereferenced ) ) ;
33
- } ) ;
35
+ specify ( 'should dereference and contain metadata about origin' , async function ( ) {
36
+ const jsonPointer = compile ( [ 'paths' , '/path1' ] ) ;
37
+ const parseResult = await parse ( fixturePath , {
38
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
39
+ } ) ;
40
+ const pathItemElement = evaluate ( jsonPointer , parseResult . api as OpenApi3_1Element ) ;
41
+ const dereferenced = await dereferenceApiDOM ( pathItemElement , {
42
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
43
+ resolve : { baseURI : `${ fixturePath } #${ jsonPointer } ` } ,
44
+ } ) ;
34
45
35
- specify ( 'should dereference and contain metadata about origin' , async function ( ) {
36
- const parseResult = await parse ( fixturePath , {
37
- parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
46
+ assert . match (
47
+ dereferenced . meta . get ( 'ref-origin' ) . toValue ( ) ,
48
+ / i n t e r n a l - o n l y \/ r o o t \. j s o n $ / ,
49
+ ) ;
38
50
} ) ;
39
- const pathItemElement = evaluate (
40
- compile ( [ 'paths' , '/path1' ] ) ,
41
- parseResult . api as OpenApi3_1Element ,
42
- ) ;
43
- const dereferenced = await dereferenceApiDOM ( pathItemElement , {
44
- parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
45
- resolve : { baseURI : fixturePath } ,
51
+ } ,
52
+ ) ;
53
+
54
+ context (
55
+ 'given single PathItemElement passed to dereferenceApiDOM with external references' ,
56
+ function ( ) {
57
+ const fixturePath = path . join ( __dirname , 'fixtures' , 'external-only' , 'root.json' ) ;
58
+
59
+ specify ( 'should dereference' , async function ( ) {
60
+ const parseResult = await parse ( fixturePath , {
61
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
62
+ } ) ;
63
+ const pathItemElement = evaluate (
64
+ compile ( [ 'paths' , '/path1' ] ) ,
65
+ parseResult . api as OpenApi3_1Element ,
66
+ ) ;
67
+ const dereferenced = await dereferenceApiDOM ( pathItemElement , {
68
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
69
+ resolve : { baseURI : fixturePath } ,
70
+ } ) ;
71
+
72
+ assert . isTrue ( isPathItemElement ( dereferenced ) ) ;
46
73
} ) ;
47
74
48
- assert . match ( dereferenced . meta . get ( 'ref-origin' ) . toValue ( ) , / e x t e r n a l - o n l y \/ e x \. j s o n $ / ) ;
49
- } ) ;
50
- } ) ;
75
+ specify ( 'should dereference and contain metadata about origin' , async function ( ) {
76
+ const parseResult = await parse ( fixturePath , {
77
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
78
+ } ) ;
79
+ const pathItemElement = evaluate (
80
+ compile ( [ 'paths' , '/path1' ] ) ,
81
+ parseResult . api as OpenApi3_1Element ,
82
+ ) ;
83
+ const dereferenced = await dereferenceApiDOM ( pathItemElement , {
84
+ parse : { mediaType : mediaTypes . latest ( 'json' ) } ,
85
+ resolve : { baseURI : fixturePath } ,
86
+ } ) ;
87
+
88
+ assert . match (
89
+ dereferenced . meta . get ( 'ref-origin' ) . toValue ( ) ,
90
+ / e x t e r n a l - o n l y \/ e x \. j s o n $ / ,
91
+ ) ;
92
+ } ) ;
93
+ } ,
94
+ ) ;
51
95
} ) ;
52
96
} ) ;
53
97
} ) ;
0 commit comments