Skip to content

Commit 593b9b5

Browse files
committed
Fix resolvers not updating properly when referencing other files.
Issue #893
1 parent 2e98965 commit 593b9b5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

openapi_core/validation/schemas/validators.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ def validate(self, value: Any) -> None:
3838
def evolve(self, schema: SchemaPath) -> "SchemaValidator":
3939
cls = self.__class__
4040

41-
with schema.open() as schema_dict:
42-
return cls(schema, self.validator.evolve(schema=schema_dict))
41+
with schema.resolve() as resolved:
42+
validator = self.validator.evolve(
43+
schema=resolved.contents, _resolver=resolved.resolver
44+
)
45+
return cls(schema, validator)
4346

4447
def type_validator(
4548
self, value: Any, type_override: Optional[str] = None

tests/integration/validation/test_parent_reference.py

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from openapi_core import Config
77
from openapi_core import OpenAPI
8+
from openapi_core import V30ResponseUnmarshaller
89
from openapi_core.testing import MockRequest
910
from openapi_core.testing import MockResponse
1011

@@ -13,6 +14,13 @@ class TestParentReference:
1314

1415
spec_path = "data/v3.0/parent-reference/openapi.yaml"
1516

17+
@pytest.fixture
18+
def unmarshaller(self, content_factory):
19+
content, base_uri = content_factory.from_file(self.spec_path)
20+
return V30ResponseUnmarshaller(
21+
spec=SchemaPath.from_dict(content, base_uri=base_uri)
22+
)
23+
1624
@pytest.fixture
1725
def openapi(self, content_factory):
1826
content, base_uri = content_factory.from_file(self.spec_path)
@@ -27,3 +35,11 @@ def test_valid(self, openapi):
2735
)
2836

2937
openapi.validate_response(request, response)
38+
39+
def test_unmarshal(self, unmarshaller):
40+
request = MockRequest(host_url="", method="GET", path="/books")
41+
response = MockResponse(
42+
data=json.dumps([{"id": "BOOK:01", "title": "Test Book"}]).encode()
43+
)
44+
45+
unmarshaller.unmarshal(request, response)

0 commit comments

Comments
 (0)