This repository was archived by the owner on Jul 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +72
-1
lines changed Expand file tree Collapse file tree 2 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,70 @@ describe('resolver', () => {
173173 expect ( resolved . result ) . toEqual ( source ) ;
174174 } ) ;
175175
176+ test ( 'resolvePointers option should force to true for remote authorities' , async ( ) => {
177+ const data = {
178+ oas : {
179+ swagger : '2.0' ,
180+ definitions : {
181+ user : {
182+ address : {
183+ $ref : '#/definitions/address' ,
184+ } ,
185+ } ,
186+ address : {
187+ title : 'Address' ,
188+ } ,
189+ } ,
190+ } ,
191+ } ;
192+
193+ const fileReader : Types . IReader = {
194+ async read ( ) : Promise < any > {
195+ return data . oas ;
196+ } ,
197+ } ;
198+
199+ const source = {
200+ definitions : {
201+ foo : {
202+ $ref : '#/definitions/bar' ,
203+ } ,
204+ bar : {
205+ title : 'bar' ,
206+ } ,
207+ someOASFile : {
208+ $ref : './main.oas2.yml#/definitions/user' ,
209+ } ,
210+ } ,
211+ } ;
212+
213+ const resolver = new Resolver ( {
214+ readers : {
215+ file : fileReader ,
216+ } ,
217+ } ) ;
218+
219+ const result = await resolver . resolve ( source , {
220+ resolvePointers : false ,
221+ } ) ;
222+
223+ expect ( result . result ) . toEqual ( {
224+ definitions : {
225+ foo : {
226+ $ref : '#/definitions/bar' ,
227+ } ,
228+ bar : {
229+ title : 'bar' ,
230+ } ,
231+ someOASFile : {
232+ address : {
233+ title : 'Address' ,
234+ } ,
235+ } ,
236+ } ,
237+ } ) ;
238+ } ) ;
239+
176240 test ( 'should support chained jsonPointers + partial resolution' , async ( ) => {
177241 const source = {
178242 hello : {
Original file line number Diff line number Diff line change @@ -60,7 +60,14 @@ export class ResolveRunner implements Types.IResolveRunner {
6060 this . readers = opts . readers || { } ;
6161 this . getRef = opts . getRef || defaultGetRef ;
6262 this . transformRef = opts . transformRef ;
63- this . resolvePointers = typeof opts . resolvePointers !== 'undefined' ? opts . resolvePointers : true ;
63+ // Need to resolve pointers if depth is greater than zero because that means the autority has changed, and the
64+ // local refs need to be resolved.
65+ if ( this . depth ) {
66+ this . resolvePointers = true ;
67+ } else {
68+ this . resolvePointers = typeof opts . resolvePointers !== 'undefined' ? opts . resolvePointers : true ;
69+ }
70+
6471 this . resolveAuthorities = typeof opts . resolveAuthorities !== 'undefined' ? opts . resolveAuthorities : true ;
6572 this . parseAuthorityResult = opts . parseAuthorityResult ;
6673 this . ctx = opts . ctx ;
You can’t perform that action at this time.
0 commit comments