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, ) 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)