Skip to content

Commit 3a198a6

Browse files
authored
Merge pull request #232 from python-openapi/fix/update-supports-validation-protocol
Update SupportsValidation protocol
2 parents 37e3de3 + 408a412 commit 3a198a6

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

Diff for: openapi_spec_validator/shortcuts.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any
33
from typing import Hashable
44
from typing import Mapping
5+
from typing import Optional
56

67
from jsonschema_spec.handlers import all_urls_handler
78

@@ -11,15 +12,16 @@
1112

1213
def validate_spec(
1314
spec: Mapping[Hashable, Any],
14-
spec_url: str = "",
15+
base_uri: str = "",
1516
validator: SupportsValidation = openapi_spec_validator_proxy,
17+
spec_url: Optional[str] = None,
1618
) -> None:
17-
return validator.validate(spec, spec_url=spec_url)
19+
return validator.validate(spec, base_uri=base_uri, spec_url=spec_url)
1820

1921

2022
def validate_spec_url(
2123
spec_url: str,
2224
validator: SupportsValidation = openapi_spec_validator_proxy,
2325
) -> None:
2426
spec = all_urls_handler(spec_url)
25-
return validator.validate(spec, spec_url=spec_url)
27+
return validator.validate(spec, base_uri=spec_url)

Diff for: openapi_spec_validator/validation/protocols.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Hashable
33
from typing import Iterator
44
from typing import Mapping
5+
from typing import Optional
56
from typing import Protocol
67
from typing import runtime_checkable
78

@@ -14,11 +15,17 @@ def is_valid(self, instance: Mapping[Hashable, Any]) -> bool:
1415
...
1516

1617
def iter_errors(
17-
self, instance: Mapping[Hashable, Any], spec_url: str = ""
18+
self,
19+
instance: Mapping[Hashable, Any],
20+
base_uri: str = "",
21+
spec_url: Optional[str] = None,
1822
) -> Iterator[OpenAPIValidationError]:
1923
...
2024

2125
def validate(
22-
self, instance: Mapping[Hashable, Any], spec_url: str = ""
26+
self,
27+
instance: Mapping[Hashable, Any],
28+
base_uri: str = "",
29+
spec_url: Optional[str] = None,
2330
) -> None:
2431
...

Diff for: openapi_spec_validator/validation/proxies.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import Hashable
44
from typing import Iterator
55
from typing import Mapping
6+
from typing import Optional
67
from typing import Tuple
78

89
from openapi_spec_validator.validation.exceptions import OpenAPIValidationError
@@ -21,10 +22,15 @@ def detect(self, instance: Mapping[Hashable, Any]) -> SpecValidator:
2122
raise ValidatorDetectError("Spec schema version not detected")
2223

2324
def validate(
24-
self, instance: Mapping[Hashable, Any], spec_url: str = ""
25+
self,
26+
instance: Mapping[Hashable, Any],
27+
base_uri: str = "",
28+
spec_url: Optional[str] = None,
2529
) -> None:
2630
validator = self.detect(instance)
27-
for err in validator.iter_errors(instance, spec_url=spec_url):
31+
for err in validator.iter_errors(
32+
instance, base_uri=base_uri, spec_url=spec_url
33+
):
2834
raise err
2935

3036
def is_valid(self, instance: Mapping[Hashable, Any]) -> bool:
@@ -33,7 +39,12 @@ def is_valid(self, instance: Mapping[Hashable, Any]) -> bool:
3339
return error is None
3440

3541
def iter_errors(
36-
self, instance: Mapping[Hashable, Any], spec_url: str = ""
42+
self,
43+
instance: Mapping[Hashable, Any],
44+
base_uri: str = "",
45+
spec_url: Optional[str] = None,
3746
) -> Iterator[OpenAPIValidationError]:
3847
validator = self.detect(instance)
39-
yield from validator.iter_errors(instance, spec_url=spec_url)
48+
yield from validator.iter_errors(
49+
instance, base_uri=base_uri, spec_url=spec_url
50+
)

0 commit comments

Comments
 (0)