@@ -96,11 +96,12 @@ def _collect_properties(self, schema: SchemaPath) -> set[str]:
9696 def __call__ (
9797 self , schema : SchemaPath , require_properties : bool = True
9898 ) -> Iterator [ValidationError ]:
99- if not hasattr (schema .content (), "__getitem__" ):
99+ schema_value = schema .read_value ()
100+ if not hasattr (schema_value , "__getitem__" ):
100101 return
101102
102103 assert self .schema_ids_registry is not None
103- schema_id = id (schema . content () )
104+ schema_id = id (schema_value )
104105 if schema_id in self .schema_ids_registry :
105106 return
106107 self .schema_ids_registry .append (schema_id )
@@ -151,8 +152,8 @@ def __call__(
151152 require_properties = False ,
152153 )
153154
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 []
156157 if "allOf" in schema :
157158 extra_properties = list (
158159 set (required ) - set (properties ) - set (nested_properties )
@@ -166,10 +167,12 @@ def __call__(
166167 )
167168
168169 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 )
173176
174177
175178class SchemasValidator (KeywordValidator ):
@@ -203,9 +206,9 @@ def __call__(self, parameter: SchemaPath) -> Iterator[ValidationError]:
203206
204207 if "default" in parameter :
205208 # 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 )
209212
210213
211214class ParametersValidator (KeywordValidator ):
@@ -317,15 +320,17 @@ def __call__(
317320 ) -> Iterator [ValidationError ]:
318321 assert self .operation_ids_registry is not None
319322
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 )
329334
330335 if "responses" in operation :
331336 responses = operation / "responses"
@@ -416,8 +421,9 @@ def schemas_validator(self) -> SchemasValidator:
416421 return cast (SchemasValidator , self .registry ["schemas" ])
417422
418423 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 )
421427
422428
423429class RootValidator (KeywordValidator ):
0 commit comments