Skip to content

Fix resolver for jsonschema validator created by SchemaValidatorsFactory #853

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 2 commits into from
Jun 20, 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: 3 additions & 4 deletions openapi_core/validation/schemas/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
7 changes: 7 additions & 0 deletions tests/integration/data/v3.0/parent-reference/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
openapi: "3.0.0"
info:
title: sample
version: "0.1"
paths:
/books:
$ref: "./paths/books.yaml"
10 changes: 10 additions & 0 deletions tests/integration/data/v3.0/parent-reference/paths/books.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
get:
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "../schemas/book.yaml#/Book"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Book:
type: object
properties:
id:
$ref: "#/BookId"
title:
type: string
BookId:
type: string
29 changes: 29 additions & 0 deletions tests/integration/validation/test_parent_reference.py
Original file line number Diff line number Diff line change
@@ -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)
Loading