@@ -37,9 +37,14 @@ describe("options.resolve", () => {
3737 foo : {
3838 canRead : / ^ f o o \: \/ \/ / i,
3939 read : { bar : { baz : "hello world" } }
40+ } ,
41+ bar : {
42+ canRead : / ^ b a r \: \/ \/ / i,
43+ read : { Foo : { Baz : "hello world" } }
4044 }
4145 }
4246 } ) ;
47+
4348 expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
4449 } ) ;
4550
@@ -53,12 +58,44 @@ describe("options.resolve", () => {
5358 read ( _file ) {
5459 return { bar : { baz : "hello world" } } ;
5560 }
61+ } ,
62+ bar : {
63+ canRead : / ^ b a r \: \/ \/ / i,
64+ read ( _file ) {
65+ return { Foo : { Baz : "hello world" } } ;
66+ }
5667 }
5768 }
5869 } ) ;
5970 expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
6071 } ) ;
6172
73+ it ( "should return _file url as it's written" , async ( ) => {
74+ const schema = await $RefParser
75+ . dereference ( path . abs ( "specs/resolvers/resolvers.yaml" ) , {
76+ resolve : {
77+ // A custom resolver for "foo://" URLs
78+ foo : {
79+ canRead : / ^ f o o \: \/ \/ / i,
80+ read ( _file ) {
81+ return { bar : { baz : "hello world" } } ;
82+ }
83+ } ,
84+ // A custom resolver with uppercase symbols
85+ bar : {
86+ canRead : / ^ b a r \: \/ \/ / i,
87+ read ( _file ) {
88+ expect ( _file . url ) . to . be . equal ( "bar://Foo.Baz" ) ;
89+
90+ return { Foo : { Baz : "hello world" } } ;
91+ }
92+ }
93+ }
94+ } ) ;
95+
96+ expect ( schema ) . to . deep . equal ( dereferencedSchema ) ;
97+ } ) ;
98+
6299 it ( "should use a custom resolver that calls a callback" , async ( ) => {
63100 const schema = await $RefParser
64101 . dereference ( path . abs ( "specs/resolvers/resolvers.yaml" ) , {
@@ -69,6 +106,12 @@ describe("options.resolve", () => {
69106 read ( _file , callback ) {
70107 callback ( null , { bar : { baz : "hello world" } } ) ;
71108 }
109+ } ,
110+ bar : {
111+ canRead : / ^ b a r \: \/ \/ / i,
112+ read ( _file , callback ) {
113+ callback ( null , { Foo : { Baz : "hello world" } } ) ;
114+ }
72115 }
73116 }
74117 } ) ;
@@ -86,6 +129,12 @@ describe("options.resolve", () => {
86129 read ( _file ) {
87130 return Promise . resolve ( { bar : { baz : "hello world" } } ) ;
88131 }
132+ } ,
133+ bar : {
134+ canRead : / ^ b a r \: \/ \/ / i,
135+ read ( _file ) {
136+ return Promise . resolve ( { Foo : { Baz : "hello world" } } ) ;
137+ }
89138 }
90139 }
91140 } ) ;
@@ -109,6 +158,10 @@ describe("options.resolve", () => {
109158 foo : {
110159 canRead : / ^ f o o \: \/ \/ / i,
111160 read : { bar : { baz : "hello world" } }
161+ } ,
162+ bar : {
163+ canRead : / ^ b a r \: \/ \/ / i,
164+ read : { Foo : { Baz : "hello world" } }
112165 }
113166 }
114167 } ) ;
@@ -180,7 +233,7 @@ describe("options.resolve", () => {
180233 message : message => message . startsWith ( "Could not find resolver for" ) ,
181234 path : [ ] ,
182235 source : message => message . endsWith ( "specs/resolvers/resolvers.yaml" ) ,
183- } ,
236+ }
184237 ] ) ;
185238 }
186239 } ) ;
0 commit comments