@@ -96,11 +96,12 @@ def _collect_properties(self, schema: SchemaPath) -> set[str]:
96
96
def __call__ (
97
97
self , schema : SchemaPath , require_properties : bool = True
98
98
) -> Iterator [ValidationError ]:
99
- if not hasattr (schema .content (), "__getitem__" ):
99
+ schema_value = schema .read_value ()
100
+ if not hasattr (schema_value , "__getitem__" ):
100
101
return
101
102
102
103
assert self .schema_ids_registry is not None
103
- schema_id = id (schema . content () )
104
+ schema_id = id (schema_value )
104
105
if schema_id in self .schema_ids_registry :
105
106
return
106
107
self .schema_ids_registry .append (schema_id )
@@ -151,8 +152,8 @@ def __call__(
151
152
require_properties = False ,
152
153
)
153
154
154
- required = schema . getkey ( "required" , [])
155
- properties = schema . get ( "properties" , {} ).keys ()
155
+ required = "required" in schema and ( schema / "required" ). read_value () or []
156
+ properties = "properties" in schema and ( schema / "properties" ).keys () or []
156
157
if "allOf" in schema :
157
158
extra_properties = list (
158
159
set (required ) - set (properties ) - set (nested_properties )
@@ -166,10 +167,12 @@ def __call__(
166
167
)
167
168
168
169
if "default" in schema :
169
- default = schema ["default" ]
170
- nullable = schema .get ("nullable" , False )
171
- if default is not None or nullable is not True :
172
- yield from self .default_validator (schema , default )
170
+ default_value = (schema / "default" ).read_value ()
171
+ nullable_value = False
172
+ if "nullable" in schema :
173
+ nullable_value = (schema / "nullable" ).read_value ()
174
+ if default_value is not None or nullable_value is not True :
175
+ yield from self .default_validator (schema , default_value )
173
176
174
177
175
178
class SchemasValidator (KeywordValidator ):
@@ -203,9 +206,9 @@ def __call__(self, parameter: SchemaPath) -> Iterator[ValidationError]:
203
206
204
207
if "default" in parameter :
205
208
# only possible in swagger 2.0
206
- default = parameter . getkey ( "default" )
207
- if default is not None :
208
- yield from self .default_validator (parameter , default )
209
+ if "default" in parameter :
210
+ default_value = ( parameter / "default" ). read_value ()
211
+ yield from self .default_validator (parameter , default_value )
209
212
210
213
211
214
class ParametersValidator (KeywordValidator ):
@@ -317,15 +320,17 @@ def __call__(
317
320
) -> Iterator [ValidationError ]:
318
321
assert self .operation_ids_registry is not None
319
322
320
- operation_id = operation .getkey ("operationId" )
321
- if (
322
- operation_id is not None
323
- and operation_id in self .operation_ids_registry
324
- ):
325
- yield DuplicateOperationIDError (
326
- f"Operation ID '{ operation_id } ' for '{ name } ' in '{ url } ' is not unique"
327
- )
328
- self .operation_ids_registry .append (operation_id )
323
+ if "operationId" in operation :
324
+ operation_id_value = (operation / "operationId" ).read_value ()
325
+ if (
326
+ operation_id_value is not None
327
+ and operation_id_value in self .operation_ids_registry
328
+ ):
329
+ yield DuplicateOperationIDError (
330
+ f"Operation ID '{ operation_id_value } ' for "
331
+ f"'{ name } ' in '{ url } ' is not unique"
332
+ )
333
+ self .operation_ids_registry .append (operation_id_value )
329
334
330
335
if "responses" in operation :
331
336
responses = operation / "responses"
@@ -416,8 +421,9 @@ def schemas_validator(self) -> SchemasValidator:
416
421
return cast (SchemasValidator , self .registry ["schemas" ])
417
422
418
423
def __call__ (self , components : SchemaPath ) -> Iterator [ValidationError ]:
419
- schemas = components .get ("schemas" , {})
420
- yield from self .schemas_validator (schemas )
424
+ if "schemas" in components :
425
+ schemas = components / "schemas"
426
+ yield from self .schemas_validator (schemas )
421
427
422
428
423
429
class RootValidator (KeywordValidator ):
0 commit comments