Skip to content

Fix resolvers not updating properly when referencing other files. #894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions openapi_core/validation/schemas/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def validate(self, value: Any) -> None:
def evolve(self, schema: SchemaPath) -> "SchemaValidator":
cls = self.__class__

with schema.open() as schema_dict:
return cls(schema, self.validator.evolve(schema=schema_dict))
with schema.resolve() as resolved:
validator = self.validator.evolve(
schema=resolved.contents, _resolver=resolved.resolver
)
return cls(schema, validator)

def type_validator(
self, value: Any, type_override: Optional[str] = None
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/validation/test_parent_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from openapi_core import Config
from openapi_core import OpenAPI
from openapi_core import V30ResponseUnmarshaller
from openapi_core.testing import MockRequest
from openapi_core.testing import MockResponse

Expand All @@ -13,6 +14,13 @@ class TestParentReference:

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

@pytest.fixture
def unmarshaller(self, content_factory):
content, base_uri = content_factory.from_file(self.spec_path)
return V30ResponseUnmarshaller(
spec=SchemaPath.from_dict(content, base_uri=base_uri)
)

@pytest.fixture
def openapi(self, content_factory):
content, base_uri = content_factory.from_file(self.spec_path)
Expand All @@ -27,3 +35,11 @@ def test_valid(self, openapi):
)

openapi.validate_response(request, response)

def test_unmarshal(self, unmarshaller):
request = MockRequest(host_url="", method="GET", path="/books")
response = MockResponse(
data=json.dumps([{"id": "BOOK:01", "title": "Test Book"}]).encode()
)

unmarshaller.unmarshal(request, response)
Loading