6
6
7
7
from openapi_spec_validator .exceptions import (
8
8
ParameterDuplicateError , ExtraParametersError , UnresolvableParameterError ,
9
+ OpenAPIValidationError
9
10
)
11
+ from openapi_spec_validator .decorators import ValidationErrorWrapper
10
12
from openapi_spec_validator .factories import Draft4ExtendedValidatorFactory
11
13
from openapi_spec_validator .managers import ResolverManager
12
14
13
15
log = logging .getLogger (__name__ )
14
16
17
+ wraps_errors = ValidationErrorWrapper (OpenAPIValidationError )
18
+
15
19
16
20
def is_ref (spec ):
17
21
return isinstance (spec , dict ) and '$ref' in spec
@@ -43,6 +47,7 @@ def validate(self, spec, spec_url=''):
43
47
for err in self .iter_errors (spec , spec_url = spec_url ):
44
48
raise err
45
49
50
+ @wraps_errors
46
51
def iter_errors (self , spec , spec_url = '' ):
47
52
spec_resolver = self ._get_resolver (spec_url , spec )
48
53
dereferencer = self ._get_dereferencer (spec_resolver )
@@ -81,6 +86,7 @@ class ComponentsValidator(object):
81
86
def __init__ (self , dereferencer ):
82
87
self .dereferencer = dereferencer
83
88
89
+ @wraps_errors
84
90
def iter_errors (self , components ):
85
91
components_deref = self .dereferencer .dereference (components )
86
92
@@ -97,6 +103,7 @@ class SchemasValidator(object):
97
103
def __init__ (self , dereferencer ):
98
104
self .dereferencer = dereferencer
99
105
106
+ @wraps_errors
100
107
def iter_errors (self , schemas ):
101
108
schemas_deref = self .dereferencer .dereference (schemas )
102
109
for name , schema in iteritems (schemas_deref ):
@@ -112,6 +119,7 @@ class SchemaValidator(object):
112
119
def __init__ (self , dereferencer ):
113
120
self .dereferencer = dereferencer
114
121
122
+ @wraps_errors
115
123
def iter_errors (self , schema , require_properties = True ):
116
124
schema_deref = self .dereferencer .dereference (schema )
117
125
@@ -152,6 +160,7 @@ class PathsValidator(object):
152
160
def __init__ (self , dereferencer ):
153
161
self .dereferencer = dereferencer
154
162
163
+ @wraps_errors
155
164
def iter_errors (self , paths ):
156
165
paths_deref = self .dereferencer .dereference (paths )
157
166
for url , path_item in iteritems (paths_deref ):
@@ -167,6 +176,7 @@ class PathValidator(object):
167
176
def __init__ (self , dereferencer ):
168
177
self .dereferencer = dereferencer
169
178
179
+ @wraps_errors
170
180
def iter_errors (self , url , path_item ):
171
181
path_item_deref = self .dereferencer .dereference (path_item )
172
182
@@ -186,6 +196,7 @@ class PathItemValidator(object):
186
196
def __init__ (self , dereferencer ):
187
197
self .dereferencer = dereferencer
188
198
199
+ @wraps_errors
189
200
def iter_errors (self , url , path_item ):
190
201
path_item_deref = self .dereferencer .dereference (path_item )
191
202
@@ -214,6 +225,7 @@ class OperationValidator(object):
214
225
def __init__ (self , dereferencer ):
215
226
self .dereferencer = dereferencer
216
227
228
+ @wraps_errors
217
229
def iter_errors (self , url , name , operation , path_parameters = None ):
218
230
path_parameters = path_parameters or []
219
231
operation_deref = self .dereferencer .dereference (operation )
@@ -255,6 +267,7 @@ class ParametersValidator(object):
255
267
def __init__ (self , dereferencer ):
256
268
self .dereferencer = dereferencer
257
269
270
+ @wraps_errors
258
271
def iter_errors (self , parameters ):
259
272
seen = set ()
260
273
for parameter in parameters :
@@ -278,6 +291,7 @@ class ParameterValidator(object):
278
291
def __init__ (self , dereferencer ):
279
292
self .dereferencer = dereferencer
280
293
294
+ @wraps_errors
281
295
def iter_errors (self , parameter ):
282
296
if 'schema' in parameter :
283
297
schema = parameter ['schema' ]
0 commit comments