Merge pull request #62 from Mirantis/validation-null-fix
Validation: allow None for not required fields
This commit is contained in:
commit
282659e92b
@ -69,15 +69,19 @@ def _construct_jsonschema(schema, definition_base=''):
|
|||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if schema == 'str':
|
if schema == 'str':
|
||||||
return {'type': 'string'}, {}
|
return {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, {}
|
||||||
|
|
||||||
if schema == 'str!':
|
if schema == 'str!':
|
||||||
return {'type': 'string', 'minLength': 1}, {}
|
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'}, {}
|
return {'type': 'number'}, {}
|
||||||
|
|
||||||
if schema == 'bool' or schema == 'bool!':
|
if schema == 'bool':
|
||||||
|
return {'anyOf': [{'type': 'boolean'}, {'type': 'null'}]}, {}
|
||||||
|
if schema == 'bool!':
|
||||||
return {'type': 'boolean'}, {}
|
return {'type': 'boolean'}, {}
|
||||||
|
|
||||||
if isinstance(schema, list):
|
if isinstance(schema, list):
|
||||||
|
@ -38,6 +38,12 @@ input:
|
|||||||
errors = sv.validate_resource(r)
|
errors = sv.validate_resource(r)
|
||||||
self.assertListEqual(errors.keys(), ['value-required'])
|
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):
|
def test_input_int_type(self):
|
||||||
sample_meta_dir = self.make_resource_meta("""
|
sample_meta_dir = self.make_resource_meta("""
|
||||||
id: sample
|
id: sample
|
||||||
@ -70,6 +76,12 @@ input:
|
|||||||
errors = sv.validate_resource(r)
|
errors = sv.validate_resource(r)
|
||||||
self.assertListEqual(errors.keys(), ['value-required'])
|
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):
|
def test_input_dict_type(self):
|
||||||
sample_meta_dir = self.make_resource_meta("""
|
sample_meta_dir = self.make_resource_meta("""
|
||||||
id: sample
|
id: sample
|
||||||
|
Loading…
Reference in New Issue
Block a user