@@ -64,14 +64,15 @@ function Pointer ($ref, path, friendlyPath) {
6464 *
6565 * @param {* } obj - The object that will be crawled
6666 * @param {$RefParserOptions } options
67+ * @param {string } pathFromRoot - the path of place that initiated resolving
6768 *
6869 * @returns {Pointer }
6970 * Returns a JSON pointer whose {@link Pointer#value} is the resolved value.
7071 * If resolving this value required resolving other JSON references, then
7172 * the {@link Pointer#$ref} and {@link Pointer#path} will reflect the resolution path
7273 * of the resolved value.
7374 */
74- Pointer . prototype . resolve = function ( obj , options ) {
75+ Pointer . prototype . resolve = function ( obj , options , pathFromRoot ) {
7576 let tokens = Pointer . parse ( this . path , this . originalPath ) ;
7677
7778 // Crawl the object, one token at a time
@@ -83,6 +84,10 @@ Pointer.prototype.resolve = function (obj, options) {
8384 this . path = Pointer . join ( this . path , tokens . slice ( i ) ) ;
8485 }
8586
87+ if ( typeof this . value === "object" && this . value !== null && "$ref" in this . value ) {
88+ return this ;
89+ }
90+
8691 let token = tokens [ i ] ;
8792 if ( this . value [ token ] === undefined || this . value [ token ] === null ) {
8893 this . value = null ;
@@ -94,7 +99,10 @@ Pointer.prototype.resolve = function (obj, options) {
9499 }
95100
96101 // Resolve the final value
97- resolveIf$Ref ( this , options ) ;
102+ if ( ! this . value || this . value . $ref && url . resolve ( this . path , this . value . $ref ) !== pathFromRoot ) {
103+ resolveIf$Ref ( this , options ) ;
104+ }
105+
98106 return this ;
99107} ;
100108
@@ -226,7 +234,7 @@ function resolveIf$Ref (pointer, options) {
226234 pointer . circular = true ;
227235 }
228236 else {
229- let resolved = pointer . $ref . $refs . _resolve ( $refPath , url . getHash ( pointer . path ) , options ) ;
237+ let resolved = pointer . $ref . $refs . _resolve ( $refPath , pointer . path , options ) ;
230238 pointer . indirections += resolved . indirections + 1 ;
231239
232240 if ( $Ref . isExtended$Ref ( pointer . value ) ) {
0 commit comments