14
14
from jsonschema .exceptions import ValidationError
15
15
from jsonschema .protocols import Validator
16
16
from jsonschema .validators import RefResolver
17
- from jsonschema_spec .accessors import SpecAccessor
18
- from jsonschema_spec .paths import Spec
17
+ from jsonschema_spec .accessors import ResolverAccessor
18
+ from jsonschema_spec .paths import SchemaPath
19
19
20
20
from openapi_spec_validator .validation .decorators import ValidationErrorWrapper
21
21
from openapi_spec_validator .validation .exceptions import (
@@ -84,12 +84,10 @@ def iter_errors(
84
84
) -> Iterator [ValidationError ]:
85
85
self .operation_ids_registry = []
86
86
self .schema_ids_registry = []
87
- self .resolver = self ._get_resolver (spec_url , instance )
88
87
89
88
yield from self .schema_validator .iter_errors (instance )
90
89
91
- accessor = SpecAccessor (instance , self .resolver )
92
- spec = Spec (accessor )
90
+ spec = SchemaPath .from_dict (instance , base_uri = spec_url )
93
91
if "paths" in spec :
94
92
paths = spec / "paths"
95
93
yield from self ._iter_paths_errors (paths )
@@ -98,17 +96,12 @@ def iter_errors(
98
96
components = spec / "components"
99
97
yield from self ._iter_components_errors (components )
100
98
101
- def _get_resolver (
102
- self , base_uri : str , referrer : Mapping [Hashable , Any ]
103
- ) -> RefResolver :
104
- return RefResolver (base_uri , referrer , handlers = self .resolver_handlers )
105
-
106
- def _iter_paths_errors (self , paths : Spec ) -> Iterator [ValidationError ]:
99
+ def _iter_paths_errors (self , paths : SchemaPath ) -> Iterator [ValidationError ]:
107
100
for url , path_item in paths .items ():
108
101
yield from self ._iter_path_errors (url , path_item )
109
102
110
103
def _iter_path_errors (
111
- self , url : str , path_item : Spec
104
+ self , url : str , path_item : SchemaPath
112
105
) -> Iterator [ValidationError ]:
113
106
parameters = None
114
107
if "parameters" in path_item :
@@ -127,8 +120,8 @@ def _iter_operation_errors(
127
120
self ,
128
121
url : str ,
129
122
name : str ,
130
- operation : Spec ,
131
- path_parameters : Optional [Spec ],
123
+ operation : SchemaPath ,
124
+ path_parameters : Optional [SchemaPath ],
132
125
) -> Iterator [ValidationError ]:
133
126
assert self .operation_ids_registry is not None
134
127
@@ -168,13 +161,13 @@ def _iter_operation_errors(
168
161
return
169
162
170
163
def _iter_responses_errors (
171
- self , responses : Spec
164
+ self , responses : SchemaPath
172
165
) -> Iterator [ValidationError ]:
173
166
for response_code , response in responses .items ():
174
167
yield from self ._iter_response_errors (response_code , response )
175
168
176
169
def _iter_response_errors (
177
- self , response_code : str , response : Spec
170
+ self , response_code : str , response : SchemaPath
178
171
) -> Iterator [ValidationError ]:
179
172
# openapi 2
180
173
if "schema" in response :
@@ -185,18 +178,18 @@ def _iter_response_errors(
185
178
content = response / "content"
186
179
yield from self ._iter_content_errors (content )
187
180
188
- def _iter_content_errors (self , content : Spec ) -> Iterator [ValidationError ]:
181
+ def _iter_content_errors (self , content : SchemaPath ) -> Iterator [ValidationError ]:
189
182
for mimetype , media_type in content .items ():
190
183
yield from self ._iter_media_type_errors (mimetype , media_type )
191
184
192
185
def _iter_media_type_errors (
193
- self , mimetype : str , media_type : Spec
186
+ self , mimetype : str , media_type : SchemaPath
194
187
) -> Iterator [ValidationError ]:
195
188
if "schema" in media_type :
196
189
schema = media_type / "schema"
197
190
yield from self ._iter_schema_errors (schema )
198
191
199
- def _get_path_param_names (self , params : Spec ) -> Iterator [str ]:
192
+ def _get_path_param_names (self , params : SchemaPath ) -> Iterator [str ]:
200
193
for param in params :
201
194
if param ["in" ] == "path" :
202
195
yield param ["name" ]
@@ -207,7 +200,7 @@ def _get_path_params_from_url(self, url: str) -> Iterator[str]:
207
200
return filter (None , path_params )
208
201
209
202
def _iter_parameters_errors (
210
- self , parameters : Spec
203
+ self , parameters : SchemaPath
211
204
) -> Iterator [ValidationError ]:
212
205
seen = set ()
213
206
for parameter in parameters :
@@ -221,7 +214,7 @@ def _iter_parameters_errors(
221
214
seen .add (key )
222
215
223
216
def _iter_parameter_errors (
224
- self , parameter : Spec
217
+ self , parameter : SchemaPath
225
218
) -> Iterator [ValidationError ]:
226
219
if "schema" in parameter :
227
220
schema = parameter / "schema"
@@ -234,7 +227,7 @@ def _iter_parameter_errors(
234
227
yield from self ._iter_value_errors (parameter , default )
235
228
236
229
def _iter_value_errors (
237
- self , schema : Spec , value : Any
230
+ self , schema : SchemaPath , value : Any
238
231
) -> Iterator [ValidationError ]:
239
232
with schema .open () as content :
240
233
validator = self .value_validator_class (
@@ -245,7 +238,7 @@ def _iter_value_errors(
245
238
yield from validator .iter_errors (value )
246
239
247
240
def _iter_schema_errors (
248
- self , schema : Spec , require_properties : bool = True
241
+ self , schema : SchemaPath , require_properties : bool = True
249
242
) -> Iterator [ValidationError ]:
250
243
if not hasattr (schema .content (), "__getitem__" ):
251
244
return
@@ -329,11 +322,11 @@ def _iter_schema_errors(
329
322
yield from self ._iter_value_errors (schema , default )
330
323
331
324
def _iter_components_errors (
332
- self , components : Spec
325
+ self , components : SchemaPath
333
326
) -> Iterator [ValidationError ]:
334
327
schemas = components .get ("schemas" , {})
335
328
yield from self ._iter_schemas_errors (schemas )
336
329
337
- def _iter_schemas_errors (self , schemas : Spec ) -> Iterator [ValidationError ]:
330
+ def _iter_schemas_errors (self , schemas : SchemaPath ) -> Iterator [ValidationError ]:
338
331
for _ , schema in schemas .items ():
339
332
yield from self ._iter_schema_errors (schema )
0 commit comments