Skip to content

Commit f75baf9

Browse files
committed
Deprecated spec validator fix
1 parent 1b688bb commit f75baf9

File tree

5 files changed

+142
-96
lines changed

5 files changed

+142
-96
lines changed

openapi_core/spec/paths.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import warnings
12
from typing import Any
23
from typing import Hashable
34
from typing import Mapping
45
from typing import Type
56
from typing import TypeVar
67

8+
from jsonschema.validators import _UNSET
79
from jsonschema_spec import SchemaPath
8-
from openapi_spec_validator.validation import openapi_spec_validator_proxy
10+
from openapi_spec_validator import validate
911

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

@@ -20,11 +22,22 @@ def from_dict(
2022
*args: Any,
2123
**kwargs: Any,
2224
) -> TSpec:
23-
validator = kwargs.pop("validator", openapi_spec_validator_proxy)
24-
if validator is not None:
25-
base_uri = kwargs.get("base_uri", "")
26-
spec_url = kwargs.get("spec_url")
27-
validator.validate(data, base_uri=base_uri, spec_url=spec_url)
25+
if "validator" in kwargs:
26+
warnings.warn(
27+
"validator parameter is deprecated. Use spec_validator_cls instead.",
28+
DeprecationWarning,
29+
)
30+
validator = kwargs.pop("validator", _UNSET)
31+
spec_validator_cls = kwargs.pop("spec_validator_cls", _UNSET)
32+
base_uri = kwargs.get("base_uri", "")
33+
spec_url = kwargs.get("spec_url")
34+
if spec_validator_cls is not None:
35+
if spec_validator_cls is not _UNSET:
36+
validate(data, base_uri=base_uri, cls=spec_validator_cls)
37+
elif validator is _UNSET:
38+
validate(data, base_uri=base_uri)
39+
else:
40+
validator.validate(data, base_uri=base_uri, spec_url=spec_url)
2841

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

openapi_core/unmarshalling/schemas/unmarshallers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __call__(self, value: Any) -> Optional[List[Any]]:
4545
def items_unmarshaller(self) -> "SchemaUnmarshaller":
4646
# sometimes we don't have any schema i.e. free-form objects
4747
items_schema = self.schema.get(
48-
"items", Spec.from_dict({}, validator=None)
48+
"items", Spec.from_dict({}, spec_validator_cls=None)
4949
)
5050
return self.schema_unmarshaller.evolve(items_schema)
5151

@@ -120,7 +120,7 @@ def _unmarshal_properties(
120120
# free-form object
121121
if additional_properties is True:
122122
additional_prop_schema = Spec.from_dict(
123-
{"nullable": True}, validator=None
123+
{"nullable": True}, spec_validator_cls=None
124124
)
125125
# defined schema
126126
else:

poetry.lock

Lines changed: 23 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ isodate = "*"
6868
more-itertools = "*"
6969
parse = "*"
7070
openapi-schema-validator = "^0.6.0"
71-
openapi-spec-validator = "^0.6.0"
71+
openapi-spec-validator = "^0.7.1"
7272
requests = {version = "*", optional = true}
7373
werkzeug = "*"
7474
jsonschema-spec = "^0.2.3"

0 commit comments

Comments
 (0)