diff --git a/swagger_spec_validator/validator20.py b/swagger_spec_validator/validator20.py
index 381e9e4..8048241 100644
--- a/swagger_spec_validator/validator20.py
+++ b/swagger_spec_validator/validator20.py
@@ -85,9 +85,15 @@ def validate_references(raw_spec, deref, path=None, visited_spec_ids=None):
         # Due to _looks like_ we need to almost duplicate the check by removing the string enforcement
         validate_ref(ref_dict=raw_spec, path=path)
 
-    if is_ref(raw_spec):
-        if isinstance(raw_spec['$ref'], string_types):
-            validate_references(deref(raw_spec), deref, path, visited_spec_ids)
+    if is_ref(raw_spec) and 'x-scope' in raw_spec:
+        # Ensure that we're following references only if they were already
+        # descended by jsonschema during initial schema validation (x-scope is present)
+        # This is mostly done to ensure that we're not causing RefResolutionError
+        # due to the fact that the reference is relative and we have no information
+        # about the base path.
+        # This could be handled differently but we thought that checking references that
+        # were actively part of the specs is a valid trade-off here
+        validate_references(deref(raw_spec), deref, path, visited_spec_ids)
     elif isinstance(raw_spec, dict):
         for k, v in sorted(iteritems(raw_spec)):
             validate_references(v, deref, path + [k], visited_spec_ids)

Identified regression on version 2.4.2
swagger_spec_validator==2.4.2 introduced a regression while validating swagger spec split in multiple files.

The regression is caused by dereferencing references without keeping into account the scope (in which file was the reference defined)

diff --git a/tests/data/v2.0/test_complicated_refs/operations/operations.json b/tests/data/v2.0/test_complicated_refs/operations/operations.json
index 8f49353..7fc34d2 100644
--- a/tests/data/v2.0/test_complicated_refs/operations/operations.json
+++ b/tests/data/v2.0/test_complicated_refs/operations/operations.json
@@ -14,6 +14,11 @@
             },
             "tags": [
                 "pingpong"
+            ],
+            "x-something": [
+                {
+                    "$ref": "../responses/responses.json#/pong"
+                }
             ]
         }
     }
diff --git a/tests/validator20/validate_spec_url_test.py b/tests/validator20/validate_spec_url_test.py
index 27da6c2..f7f7a50 100644
--- a/tests/validator20/validate_spec_url_test.py
+++ b/tests/validator20/validate_spec_url_test.py
@@ -36,6 +36,11 @@ def test_success_crossref_url_json():
     validate_spec_url(urlpath)
 
 
+def test_complicated_refs_json():
+    urlpath = get_uri_from_file_path(os.path.abspath('./tests/data/v2.0/test_complicated_refs/swagger.json'))
+    validate_spec_url(urlpath)
+
+
 def test_specs_with_empty_reference():
     with pytest.warns(SwaggerValidationWarning) as warninfo:
         validate_spec_url(

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
3.6
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
httpretty==1.1.4
importlib-metadata==4.8.3
iniconfig==1.1.1
jsonschema==3.2.0
mock==5.2.0
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pyrsistent==0.18.0
pytest==7.0.1
PyYAML==6.0.1
six==1.17.0
-e git+https://github.com/Yelp/swagger_spec_validator.git@7bdb9507f5df9ed22cabf6474cac0864ff386d09#egg=swagger_spec_validator
tomli==1.2.3
typing_extensions==4.1.1
zipp==3.6.0

name: swagger_spec_validator
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - httpretty==1.1.4
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - jsonschema==3.2.0
      - mock==5.2.0
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pyrsistent==0.18.0
      - pytest==7.0.1
      - pyyaml==6.0.1
      - six==1.17.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - zipp==3.6.0
prefix: /opt/conda/envs/swagger_spec_validator

tests/validator20/validate_spec_url_test.py::test_complicated_refs_json
tests/validator20/validate_spec_url_test.py::test_success tests/validator20/validate_spec_url_test.py::test_success_crossref_url_yaml tests/validator20/validate_spec_url_test.py::test_success_crossref_url_json tests/validator20/validate_spec_url_test.py::test_specs_with_empty_reference tests/validator20/validate_spec_url_test.py::test_raise_SwaggerValidationError_on_urlopen_error
swagger_spec_validator/validator20.py
swagger_spec_validator/validator20.py