Skip to content

Deprecated spec validator fix #717

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
Nov 6, 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
25 changes: 19 additions & 6 deletions openapi_core/spec/paths.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import warnings
from typing import Any
from typing import Hashable
from typing import Mapping
from typing import Type
from typing import TypeVar

from jsonschema.validators import _UNSET
from jsonschema_spec import SchemaPath
from openapi_spec_validator.validation import openapi_spec_validator_proxy
from openapi_spec_validator import validate

TSpec = TypeVar("TSpec", bound="Spec")

Expand All @@ -20,11 +22,22 @@ def from_dict(
*args: Any,
**kwargs: Any,
) -> TSpec:
validator = kwargs.pop("validator", openapi_spec_validator_proxy)
if validator is not None:
base_uri = kwargs.get("base_uri", "")
spec_url = kwargs.get("spec_url")
validator.validate(data, base_uri=base_uri, spec_url=spec_url)
if "validator" in kwargs:
warnings.warn(
"validator parameter is deprecated. Use spec_validator_cls instead.",
DeprecationWarning,
)
validator = kwargs.pop("validator", _UNSET)
spec_validator_cls = kwargs.pop("spec_validator_cls", _UNSET)
base_uri = kwargs.get("base_uri", "")
spec_url = kwargs.get("spec_url")
if spec_validator_cls is not None:
if spec_validator_cls is not _UNSET:
validate(data, base_uri=base_uri, cls=spec_validator_cls)
elif validator is _UNSET:
validate(data, base_uri=base_uri)
elif validator is not None:
validator.validate(data, base_uri=base_uri, spec_url=spec_url)

return super().from_dict(data, *args, **kwargs)

Expand Down
4 changes: 2 additions & 2 deletions openapi_core/unmarshalling/schemas/unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __call__(self, value: Any) -> Optional[List[Any]]:
def items_unmarshaller(self) -> "SchemaUnmarshaller":
# sometimes we don't have any schema i.e. free-form objects
items_schema = self.schema.get(
"items", Spec.from_dict({}, validator=None)
"items", Spec.from_dict({}, spec_validator_cls=None)
)
return self.schema_unmarshaller.evolve(items_schema)

Expand Down Expand Up @@ -120,7 +120,7 @@ def _unmarshal_properties(
# free-form object
if additional_properties is True:
additional_prop_schema = Spec.from_dict(
{"nullable": True}, validator=None
{"nullable": True}, spec_validator_cls=None
)
# defined schema
else:
Expand Down
29 changes: 23 additions & 6 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ isodate = "*"
more-itertools = "*"
parse = "*"
openapi-schema-validator = "^0.6.0"
openapi-spec-validator = "^0.6.0"
openapi-spec-validator = "^0.7.1"
requests = {version = "*", optional = true}
werkzeug = "*"
jsonschema-spec = "^0.2.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_response_validator_path_pattern(self, response_unmarshaller):
"http://localhost/browse/12/?q=string",
json={"data": "data"},
status=200,
match_querystring=True,
headers={"X-Rate-Limit": "12"},
)
request = requests.Request(
Expand Down
10 changes: 6 additions & 4 deletions tests/integration/schema/test_spec.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from base64 import b64encode

import pytest
from openapi_spec_validator import openapi_v30_spec_validator
from openapi_spec_validator import openapi_v31_spec_validator
from openapi_spec_validator import OpenAPIV30SpecValidator
from openapi_spec_validator import OpenAPIV31SpecValidator

from openapi_core import Spec
from openapi_core import V30RequestValidator
Expand Down Expand Up @@ -32,7 +32,9 @@ def spec_dict(self, factory):
@pytest.fixture
def spec(self, spec_dict, base_uri):
return Spec.from_dict(
spec_dict, base_uri=base_uri, validator=openapi_v30_spec_validator
spec_dict,
base_uri=base_uri,
spec_validator_cls=OpenAPIV30SpecValidator,
)

@pytest.fixture
Expand Down Expand Up @@ -327,7 +329,7 @@ def spec(self, spec_dict, base_uri):
return Spec.from_dict(
spec_dict,
base_uri=base_uri,
validator=openapi_v31_spec_validator,
spec_validator_cls=OpenAPIV31SpecValidator,
)

@pytest.fixture
Expand Down
Loading