diff --git a/solar/solar/core/validation.py b/solar/solar/core/validation.py index e4efe4a0..8e12bf57 100644 --- a/solar/solar/core/validation.py +++ b/solar/solar/core/validation.py @@ -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): diff --git a/solar/solar/test/test_validation.py b/solar/solar/test/test_validation.py index 0e5339bb..65b3c129 100644 --- a/solar/solar/test/test_validation.py +++ b/solar/solar/test/test_validation.py @@ -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