Skip to content

jsonschema 4.18 compatibility #597

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
Jun 18, 2023
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
22 changes: 8 additions & 14 deletions openapi_core/spec/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Type
from typing import TypeVar

from jsonschema_spec import Spec as JsonschemaSpec
from jsonschema_spec import SchemaPath
from jsonschema_spec import default_handlers
from openapi_spec_validator.validation import openapi_spec_validator_proxy
from openapi_spec_validator.validation.protocols import SupportsValidation
Expand All @@ -17,7 +17,7 @@
SPEC_SEPARATOR = "#"


class Spec(JsonschemaSpec):
class Spec(SchemaPath):
@classmethod
def create(
cls: Type[TSpec],
Expand Down Expand Up @@ -47,21 +47,15 @@ def from_dict(
cls: Type[TSpec],
data: Mapping[Hashable, Any],
*args: Any,
spec_url: str = "",
ref_resolver_handlers: Mapping[str, Any] = default_handlers,
separator: str = SPEC_SEPARATOR,
validator: Optional[SupportsValidation] = openapi_spec_validator_proxy,
**kwargs: Any,
) -> TSpec:
validator = kwargs.pop("validator", openapi_spec_validator_proxy)
if validator is not None:
validator.validate(data, spec_url=spec_url)
base_uri = kwargs.get("base_uri", "")
spec_url = kwargs.get("spec_url")
validator.validate(data, base_uri=base_uri, spec_url=spec_url)

return super().from_dict(
data,
*args,
spec_url=spec_url,
ref_resolver_handlers=ref_resolver_handlers,
separator=separator,
)
return super().from_dict(data, *args, **kwargs)

def exists(self) -> bool:
try:
Expand Down
2 changes: 1 addition & 1 deletion openapi_core/validation/schemas/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def create(
with schema.open() as schema_dict:
jsonschema_validator = self.schema_validator_class(
schema_dict,
resolver=resolver,
_resolver=resolver,
format_checker=format_checker,
)

Expand Down
152 changes: 89 additions & 63 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ starlette = {version = ">=0.26.1,<0.29.0", optional = true}
isodate = "*"
more-itertools = "*"
parse = "*"
openapi-schema-validator = "^0.4.2"
openapi-spec-validator = "^0.5.0"
openapi-schema-validator = {version = "^0.6.0a1", allow-prereleases = true}
openapi-spec-validator = {version = "^0.6.0a2", allow-prereleases = true}
requests = {version = "*", optional = true}
werkzeug = "*"
jsonschema-spec = "^0.1.6"
jsonschema-spec = "^0.2.2"
asgiref = "^3.6.0"
jsonschema = "^4.17.3"
jsonschema = {version = "^4.18.0a1", allow-prereleases = true}
multidict = {version = "^6.0.4", optional = true}
lazy-object-proxy = "^1.7.1"

Expand Down
14 changes: 7 additions & 7 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def content_from_file(spec_file):


def spec_from_file(spec_file):
spec_dict, spec_url = content_from_file(spec_file)
return Spec.from_dict(spec_dict, spec_url=spec_url)
spec_dict, base_uri = content_from_file(spec_file)
return Spec.from_dict(spec_dict, base_uri=base_uri)


def spec_from_url(spec_url):
content = request.urlopen(spec_url)
def spec_from_url(base_uri):
content = request.urlopen(base_uri)
spec_dict = safe_load(content)
return Spec.from_dict(spec_dict, spec_url=spec_url)
return Spec.from_dict(spec_dict, base_uri=base_uri)


class Factory(dict):
Expand All @@ -47,5 +47,5 @@ def v30_petstore_content(factory):

@pytest.fixture(scope="session")
def v30_petstore_spec(v30_petstore_content):
spec_url = "file://tests/integration/data/v3.0/petstore.yaml"
return Spec.from_dict(v30_petstore_content, spec_url=spec_url)
base_uri = "file://tests/integration/data/v3.0/petstore.yaml"
return Spec.from_dict(v30_petstore_content, base_uri=base_uri)
12 changes: 6 additions & 6 deletions tests/integration/schema/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def api_key_encoded(self):
return str(api_key_bytes_enc, "utf8")

@pytest.fixture
def spec_uri(self):
def base_uri(self):
return "file://tests/integration/data/v3.0/petstore.yaml"

@pytest.fixture
Expand All @@ -30,9 +30,9 @@ def spec_dict(self, factory):
return content

@pytest.fixture
def spec(self, spec_dict, spec_uri):
def spec(self, spec_dict, base_uri):
return Spec.from_dict(
spec_dict, spec_url=spec_uri, validator=openapi_v30_spec_validator
spec_dict, base_uri=base_uri, validator=openapi_v30_spec_validator
)

@pytest.fixture
Expand Down Expand Up @@ -312,7 +312,7 @@ def api_key_encoded(self):
return str(api_key_bytes_enc, "utf8")

@pytest.fixture
def spec_uri(self):
def base_uri(self):
return "file://tests/integration/data/v3.1/webhook-example.yaml"

@pytest.fixture
Expand All @@ -323,10 +323,10 @@ def spec_dict(self, factory):
return content

@pytest.fixture
def spec(self, spec_dict, spec_uri):
def spec(self, spec_dict, base_uri):
return Spec.from_dict(
spec_dict,
spec_url=spec_uri,
base_uri=base_uri,
validator=openapi_v31_spec_validator,
)

Expand Down
Loading