Skip to content

Commit 58e06a3

Browse files
author
Daniel Grossmann-Kavanagh
committed
wrap jsonschema exceptions with OpenAPIValidationError
1 parent 7642146 commit 58e06a3

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

openapi_spec_validator/validators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import string
33

44
from jsonschema.validators import RefResolver
5-
from six import iteritems
5+
from six import iteritems, raise_from
66

77
from openapi_spec_validator.exceptions import (
88
ParameterDuplicateError, ExtraParametersError, UnresolvableParameterError,
9+
OpenAPIValidationError
910
)
1011
from openapi_spec_validator.factories import Draft4ExtendedValidatorFactory
1112
from openapi_spec_validator.managers import ResolverManager
@@ -41,7 +42,7 @@ def __init__(self, validator_factory, resolver_handlers):
4142

4243
def validate(self, spec, spec_url=''):
4344
for err in self.iter_errors(spec, spec_url=spec_url):
44-
raise err
45+
raise_from(OpenAPIValidationError(repr(err)), err)
4546

4647
def iter_errors(self, spec, spec_url=''):
4748
spec_resolver = self._get_resolver(spec_url, spec)

tests/integration/test_shortcuts.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import pytest
22

3-
from jsonschema.exceptions import ValidationError
4-
53
from openapi_spec_validator import validate_spec, validate_spec_url
64
from openapi_spec_validator import validate_v2_spec, validate_v2_spec_url
5+
from openapi_spec_validator.exceptions import OpenAPIValidationError
76

87

98
class BaseTestValidValidteV2Spec:
@@ -15,7 +14,7 @@ def test_valid(self, spec):
1514
class BaseTestFaliedValidateV2Spec:
1615

1716
def test_failed(self, spec):
18-
with pytest.raises(ValidationError):
17+
with pytest.raises(OpenAPIValidationError):
1918
validate_v2_spec(spec)
2019

2120

@@ -28,7 +27,7 @@ def test_valid(self, spec):
2827
class BaseTestFaliedValidateSpec:
2928

3029
def test_failed(self, spec):
31-
with pytest.raises(ValidationError):
30+
with pytest.raises(OpenAPIValidationError):
3231
validate_spec(spec)
3332

3433

@@ -41,7 +40,7 @@ def test_valid(self, spec_url):
4140
class BaseTestFaliedValidateV2SpecUrl:
4241

4342
def test_failed(self, spec_url):
44-
with pytest.raises(ValidationError):
43+
with pytest.raises(OpenAPIValidationError):
4544
validate_v2_spec_url(spec_url)
4645

4746

@@ -54,7 +53,7 @@ def test_valid(self, spec_url):
5453
class BaseTestFaliedValidateSpecUrl:
5554

5655
def test_failed(self, spec_url):
57-
with pytest.raises(ValidationError):
56+
with pytest.raises(OpenAPIValidationError):
5857
validate_spec_url(spec_url)
5958

6059

tests/integration/test_validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from jsonschema.exceptions import ValidationError
3+
from openapi_spec_validator.exceptions import OpenAPIValidationError
44

55

66
class BaseTestValidOpeAPIv3Validator(object):
@@ -20,7 +20,7 @@ def spec_url(self):
2020
return ''
2121

2222
def test_failed(self, validator, spec, spec_url):
23-
with pytest.raises(ValidationError):
23+
with pytest.raises(OpenAPIValidationError):
2424
validator.validate(spec, spec_url=spec_url)
2525

2626

0 commit comments

Comments
 (0)