Merge pull request #62 from Mirantis/validation-null-fix

Validation: allow None for not required fields
This commit is contained in:
Bogdan Dobrelya 2015-08-04 15:30:26 +02:00
commit 282659e92b
2 changed files with 19 additions and 3 deletions

View File

@ -69,15 +69,19 @@ def _construct_jsonschema(schema, definition_base=''):
:return:
"""
if schema == 'str':
return {'type': 'string'}, {}
return {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, {}
if schema == 'str!':
return {'type': 'string', 'minLength': 1}, {}
if schema == 'int' or schema == 'int!':
if schema == 'int':
return {'anyOf': [{'type': 'number'}, {'type': 'null'}]}, {}
if schema == 'int!':
return {'type': 'number'}, {}
if schema == 'bool' or schema == 'bool!':
if schema == 'bool':
return {'anyOf': [{'type': 'boolean'}, {'type': 'null'}]}, {}
if schema == 'bool!':
return {'type': 'boolean'}, {}
if isinstance(schema, list):

View File

@ -38,6 +38,12 @@ input:
errors = sv.validate_resource(r)
self.assertListEqual(errors.keys(), ['value-required'])
r = self.create_resource(
'r4', sample_meta_dir, {'value': None, 'value-required': 'y'}
)
errors = sv.validate_resource(r)
self.assertEqual(errors, {})
def test_input_int_type(self):
sample_meta_dir = self.make_resource_meta("""
id: sample
@ -70,6 +76,12 @@ input:
errors = sv.validate_resource(r)
self.assertListEqual(errors.keys(), ['value-required'])
r = self.create_resource(
'r4', sample_meta_dir, {'value': None, 'value-required': 2}
)
errors = sv.validate_resource(r)
self.assertEqual(errors, {})
def test_input_dict_type(self):
sample_meta_dir = self.make_resource_meta("""
id: sample