diff --git a/tiramisu_json_api/api.py b/tiramisu_json_api/api.py index c620fe4..df44d37 100644 --- a/tiramisu_json_api/api.py +++ b/tiramisu_json_api/api.py @@ -8,6 +8,11 @@ from .setting import undefined from .i18n import _ + +TYPE = {'boolean': bool, + 'number': int, + 'string': str} + class Option: # fake Option (IntOption, StrOption, ...) def __init__(self, @@ -237,6 +242,11 @@ class TiramisuOptionValue(_Value): return self.schema['enum'] def set(self, value): + if self.schema['type'] == 'choice': + if value not in self.schema['enum']: + raise Exception('value {} is not in {}'.format(value, self.schema['enum'])) + elif not isinstance(value, TYPE[self.schema['type']]): + raise Exception('value {} is not a valid {} '.format(value, self.schema['type'])) self.config.modify_value(self.path, self.index, value,