Drop definitions from schemas since they clutter log output
This commit is contained in:
parent
e861353a73
commit
d7e0009ce5
|
@ -9,15 +9,16 @@ from bigchaindb.common.exceptions import SchemaValidationError
|
|||
|
||||
def drop_schema_descriptions(node):
|
||||
""" Drop descriptions from schema, since they clutter log output """
|
||||
if isinstance(node, list):
|
||||
for val in node:
|
||||
drop_schema_descriptions(val)
|
||||
elif isinstance(node, dict):
|
||||
if node.get('type') == 'object':
|
||||
if 'description' in node:
|
||||
del node['description']
|
||||
for val in node.values():
|
||||
drop_schema_descriptions(val)
|
||||
if 'description' in node:
|
||||
del node['description']
|
||||
for n in node.get('properties', {}).values():
|
||||
drop_schema_descriptions(n)
|
||||
for n in node.get('definitions', {}).values():
|
||||
drop_schema_descriptions(n)
|
||||
for n in node.get('anyOf', []):
|
||||
drop_schema_descriptions(n)
|
||||
|
||||
|
||||
|
||||
|
||||
def _load_schema(name):
|
||||
|
@ -25,8 +26,8 @@ def _load_schema(name):
|
|||
path = os.path.join(os.path.dirname(__file__), name + '.yaml')
|
||||
with open(path) as handle:
|
||||
schema = yaml.safe_load(handle)
|
||||
drop_schema_descriptions(schema)
|
||||
return path, schema
|
||||
drop_schema_descriptions(schema)
|
||||
return path, schema
|
||||
|
||||
|
||||
def _validate_schema(schema, body):
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from copy import deepcopy
|
||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA, \
|
||||
drop_schema_descriptions
|
||||
|
||||
|
@ -29,14 +28,42 @@ def test_vote_schema_additionalproperties():
|
|||
|
||||
def test_drop_descriptions():
|
||||
node = {
|
||||
'a': 1,
|
||||
'description': 'abc',
|
||||
'b': [{
|
||||
'type': 'object',
|
||||
'description': 'gone, baby',
|
||||
}]
|
||||
'properties': {
|
||||
'description': {
|
||||
'description': ('The property named "description" should stay'
|
||||
'but description meta field goes'),
|
||||
},
|
||||
'properties': {
|
||||
'description': 'this must go'
|
||||
},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{
|
||||
'description': 'must go'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {
|
||||
'description': "go"
|
||||
}
|
||||
}
|
||||
}
|
||||
node2 = deepcopy(node)
|
||||
drop_schema_descriptions(node)
|
||||
del node2['b'][0]['description']
|
||||
assert node == node2
|
||||
expected = {
|
||||
'properties': {
|
||||
'description': {},
|
||||
'properties': {},
|
||||
'any': {
|
||||
'anyOf': [
|
||||
{}
|
||||
]
|
||||
}
|
||||
},
|
||||
'definitions': {
|
||||
'wat': {},
|
||||
}
|
||||
}
|
||||
assert node == expected
|
||||
|
|
Loading…
Reference in New Issue