mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
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):
|
def drop_schema_descriptions(node):
|
||||||
""" Drop descriptions from schema, since they clutter log output """
|
""" Drop descriptions from schema, since they clutter log output """
|
||||||
if isinstance(node, list):
|
if 'description' in node:
|
||||||
for val in node:
|
del node['description']
|
||||||
drop_schema_descriptions(val)
|
for n in node.get('properties', {}).values():
|
||||||
elif isinstance(node, dict):
|
drop_schema_descriptions(n)
|
||||||
if node.get('type') == 'object':
|
for n in node.get('definitions', {}).values():
|
||||||
if 'description' in node:
|
drop_schema_descriptions(n)
|
||||||
del node['description']
|
for n in node.get('anyOf', []):
|
||||||
for val in node.values():
|
drop_schema_descriptions(n)
|
||||||
drop_schema_descriptions(val)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _load_schema(name):
|
def _load_schema(name):
|
||||||
@ -25,8 +26,8 @@ def _load_schema(name):
|
|||||||
path = os.path.join(os.path.dirname(__file__), name + '.yaml')
|
path = os.path.join(os.path.dirname(__file__), name + '.yaml')
|
||||||
with open(path) as handle:
|
with open(path) as handle:
|
||||||
schema = yaml.safe_load(handle)
|
schema = yaml.safe_load(handle)
|
||||||
drop_schema_descriptions(schema)
|
drop_schema_descriptions(schema)
|
||||||
return path, schema
|
return path, schema
|
||||||
|
|
||||||
|
|
||||||
def _validate_schema(schema, body):
|
def _validate_schema(schema, body):
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from copy import deepcopy
|
|
||||||
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA, \
|
from bigchaindb.common.schema import TX_SCHEMA, VOTE_SCHEMA, \
|
||||||
drop_schema_descriptions
|
drop_schema_descriptions
|
||||||
|
|
||||||
@ -29,14 +28,42 @@ def test_vote_schema_additionalproperties():
|
|||||||
|
|
||||||
def test_drop_descriptions():
|
def test_drop_descriptions():
|
||||||
node = {
|
node = {
|
||||||
'a': 1,
|
|
||||||
'description': 'abc',
|
'description': 'abc',
|
||||||
'b': [{
|
'properties': {
|
||||||
'type': 'object',
|
'description': {
|
||||||
'description': 'gone, baby',
|
'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)
|
drop_schema_descriptions(node)
|
||||||
del node2['b'][0]['description']
|
expected = {
|
||||||
assert node == node2
|
'properties': {
|
||||||
|
'description': {},
|
||||||
|
'properties': {},
|
||||||
|
'any': {
|
||||||
|
'anyOf': [
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'definitions': {
|
||||||
|
'wat': {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert node == expected
|
||||||
|
Loading…
x
Reference in New Issue
Block a user