ЛР4 - БПИ2303 - Стругов - на 4
This commit is contained in:
+5
-1
@@ -49,7 +49,11 @@ def validate(value, schema, where='response'):
|
||||
check(value == schema['const'], where + ': invalid const')
|
||||
if isinstance(value,dict):
|
||||
props = schema.get('properties',{})
|
||||
check(all(k in value for k in schema.get('required',[])), where + ': missing required fields')
|
||||
missing = set(schema.get('required', [])) - set(value)
|
||||
check(
|
||||
not missing,
|
||||
f"{where}: missing required fields {sorted(missing)}; received fields {sorted(value)}"
|
||||
)
|
||||
if schema.get('additionalProperties') is False:
|
||||
check(not set(value).difference(props), where + ': unexpected fields')
|
||||
for key, sub in props.items():
|
||||
|
||||
Reference in New Issue
Block a user