66
77from openapi_spec_validator .exceptions import (
88 ParameterDuplicateError , ExtraParametersError , UnresolvableParameterError ,
9+ OpenAPIValidationError
910)
11+ from openapi_spec_validator .decorators import ValidationErrorWrapper
1012from openapi_spec_validator .factories import Draft4ExtendedValidatorFactory
1113from openapi_spec_validator .managers import ResolverManager
1214
1315log = logging .getLogger (__name__ )
1416
17+ wraps_errors = ValidationErrorWrapper (OpenAPIValidationError )
18+
1519
1620def is_ref (spec ):
1721 return isinstance (spec , dict ) and '$ref' in spec
@@ -43,6 +47,7 @@ def validate(self, spec, spec_url=''):
4347 for err in self .iter_errors (spec , spec_url = spec_url ):
4448 raise err
4549
50+ @wraps_errors
4651 def iter_errors (self , spec , spec_url = '' ):
4752 spec_resolver = self ._get_resolver (spec_url , spec )
4853 dereferencer = self ._get_dereferencer (spec_resolver )
@@ -81,6 +86,7 @@ class ComponentsValidator(object):
8186 def __init__ (self , dereferencer ):
8287 self .dereferencer = dereferencer
8388
89+ @wraps_errors
8490 def iter_errors (self , components ):
8591 components_deref = self .dereferencer .dereference (components )
8692
@@ -97,6 +103,7 @@ class SchemasValidator(object):
97103 def __init__ (self , dereferencer ):
98104 self .dereferencer = dereferencer
99105
106+ @wraps_errors
100107 def iter_errors (self , schemas ):
101108 schemas_deref = self .dereferencer .dereference (schemas )
102109 for name , schema in iteritems (schemas_deref ):
@@ -112,6 +119,7 @@ class SchemaValidator(object):
112119 def __init__ (self , dereferencer ):
113120 self .dereferencer = dereferencer
114121
122+ @wraps_errors
115123 def iter_errors (self , schema , require_properties = True ):
116124 schema_deref = self .dereferencer .dereference (schema )
117125
@@ -152,6 +160,7 @@ class PathsValidator(object):
152160 def __init__ (self , dereferencer ):
153161 self .dereferencer = dereferencer
154162
163+ @wraps_errors
155164 def iter_errors (self , paths ):
156165 paths_deref = self .dereferencer .dereference (paths )
157166 for url , path_item in iteritems (paths_deref ):
@@ -167,6 +176,7 @@ class PathValidator(object):
167176 def __init__ (self , dereferencer ):
168177 self .dereferencer = dereferencer
169178
179+ @wraps_errors
170180 def iter_errors (self , url , path_item ):
171181 path_item_deref = self .dereferencer .dereference (path_item )
172182
@@ -186,6 +196,7 @@ class PathItemValidator(object):
186196 def __init__ (self , dereferencer ):
187197 self .dereferencer = dereferencer
188198
199+ @wraps_errors
189200 def iter_errors (self , url , path_item ):
190201 path_item_deref = self .dereferencer .dereference (path_item )
191202
@@ -214,6 +225,7 @@ class OperationValidator(object):
214225 def __init__ (self , dereferencer ):
215226 self .dereferencer = dereferencer
216227
228+ @wraps_errors
217229 def iter_errors (self , url , name , operation , path_parameters = None ):
218230 path_parameters = path_parameters or []
219231 operation_deref = self .dereferencer .dereference (operation )
@@ -255,6 +267,7 @@ class ParametersValidator(object):
255267 def __init__ (self , dereferencer ):
256268 self .dereferencer = dereferencer
257269
270+ @wraps_errors
258271 def iter_errors (self , parameters ):
259272 seen = set ()
260273 for parameter in parameters :
@@ -278,6 +291,7 @@ class ParameterValidator(object):
278291 def __init__ (self , dereferencer ):
279292 self .dereferencer = dereferencer
280293
294+ @wraps_errors
281295 def iter_errors (self , parameter ):
282296 if 'schema' in parameter :
283297 schema = parameter ['schema' ]
0 commit comments