Repository: python-openapi/openapi-core (language: python)

Issue:
[Bug]: `_validate_reference` cannot resolve $ref with a relative file path
### Actual Behavior

`openapi.validate_response` raises `jsonschema.exceptions._WrappedReferencingError` when the response schema defined in a different file includes `$ref` that refers to a schema in another file.

### Expected Behavior

The validator should not raise the error for `$ref`.
I ensured no spec-related error occured when `openapi.check_spec()` called.

### Steps to Reproduce

**openapi.yaml**
```yaml
openapi: "3.0.0"
info:
  title: sample
  version: "0.1"
paths:
  /books:
    $ref: "./paths/books.yaml"
```

**paths/books.yaml**
```yaml
get:
  responses:
    "200":
      description: OK
      content:
        application/json:
          schema:
            type: array
            items:
              $ref: "../schemas/book.yaml#/Book"
```

**schemas/book.yaml**
```yaml
Book:
  type: object
  properties:
    id:
      $ref: "#/BookId"
    title:
      type: string
BookId:
  type: string
```

**validate.py**
```py
import json
import os

import openapi_core
import openapi_core.testing

SPEC_PATH = os.path.join(os.path.dirname(__file__), "openapi.yaml")

openapi = openapi_core.OpenAPI.from_file_path(
    SPEC_PATH,
    config=openapi_core.Config(spec_base_uri=f"file://{SPEC_PATH}"),
)
openapi.check_spec()  # ensure the spec is valid

request = openapi_core.testing.MockRequest(
    host_url="", method="GET", path="/books"
)
response = openapi_core.testing.MockResponse(
    data=json.dumps([{"id": "BOOK:01", "title": "Test Book"}]).encode()
)
openapi.validate_request(request)
openapi.validate_response(request, response)  # raises error
```

Run:
```sh
$ python validate.py
```

### OpenAPI Core Version

3.0.0,3.1.0

### OpenAPI Core Integration

Nothing

### Affected Area(s)

validation

### References

_No response_

### Anything else we need to know?

_No response_

### Would you like to implement a fix?

Yes


Discussion / hints:

Fix patch:
diff --git a/openapi_core/validation/schemas/factories.py b/openapi_core/validation/schemas/factories.py
index a71d5139..11be59a5 100644
--- a/openapi_core/validation/schemas/factories.py
+++ b/openapi_core/validation/schemas/factories.py
@@ -57,11 +57,10 @@ def create(
         format_checker = self.get_format_checker(
             format_validators, extra_format_validators
         )
-        resolver = schema.accessor.resolver  # type: ignore
-        with schema.open() as schema_dict:
+        with schema.resolve() as resolved:
             jsonschema_validator = self.schema_validator_class(
-                schema_dict,
-                _resolver=resolver,
+                resolved.contents,
+                _resolver=resolved.resolver,
                 format_checker=format_checker,
             )
 


Test patch:
diff --git a/tests/integration/data/v3.0/parent-reference/openapi.yaml b/tests/integration/data/v3.0/parent-reference/openapi.yaml
new file mode 100644
index 00000000..51150416
--- /dev/null
+++ b/tests/integration/data/v3.0/parent-reference/openapi.yaml
@@ -0,0 +1,7 @@
+openapi: "3.0.0"
+info:
+  title: sample
+  version: "0.1"
+paths:
+  /books:
+    $ref: "./paths/books.yaml"
\ No newline at end of file
diff --git a/tests/integration/data/v3.0/parent-reference/paths/books.yaml b/tests/integration/data/v3.0/parent-reference/paths/books.yaml
new file mode 100644
index 00000000..d625f4f5
--- /dev/null
+++ b/tests/integration/data/v3.0/parent-reference/paths/books.yaml
@@ -0,0 +1,10 @@
+get:
+  responses:
+    "200":
+      description: OK
+      content:
+        application/json:
+          schema:
+            type: array
+            items:
+              $ref: "../schemas/book.yaml#/Book"
\ No newline at end of file
diff --git a/tests/integration/data/v3.0/parent-reference/schemas/book.yaml b/tests/integration/data/v3.0/parent-reference/schemas/book.yaml
new file mode 100644
index 00000000..1bf35402
--- /dev/null
+++ b/tests/integration/data/v3.0/parent-reference/schemas/book.yaml
@@ -0,0 +1,9 @@
+Book:
+  type: object
+  properties:
+    id:
+      $ref: "#/BookId"
+    title:
+      type: string
+BookId:
+  type: string
\ No newline at end of file
diff --git a/tests/integration/validation/test_parent_reference.py b/tests/integration/validation/test_parent_reference.py
new file mode 100644
index 00000000..df526835
--- /dev/null
+++ b/tests/integration/validation/test_parent_reference.py
@@ -0,0 +1,29 @@
+import json
+
+import pytest
+from jsonschema_path import SchemaPath
+
+from openapi_core import Config
+from openapi_core import OpenAPI
+from openapi_core.testing import MockRequest
+from openapi_core.testing import MockResponse
+
+
+class TestParentReference:
+
+    spec_path = "data/v3.0/parent-reference/openapi.yaml"
+
+    @pytest.fixture
+    def openapi(self, content_factory):
+        content, base_uri = content_factory.from_file(self.spec_path)
+        spec = SchemaPath.from_dict(content, base_uri=base_uri)
+        config = Config(spec_base_uri=base_uri)
+        return OpenAPI(spec, config=config)
+
+    def test_valid(self, openapi):
+        request = MockRequest(host_url="", method="GET", path="/books")
+        response = MockResponse(
+            data=json.dumps([{"id": "BOOK:01", "title": "Test Book"}]).encode()
+        )
+
+        openapi.validate_response(request, response)