raw json cares about value types

This commit is contained in:
iLLiCiTiT 2021-03-22 09:54:52 +01:00
parent 4fc12b8c08
commit 89ee780d79
2 changed files with 26 additions and 5 deletions

View file

@ -380,13 +380,30 @@ class RawJsonEntity(InputEntity):
def _item_initalization(self):
# Schema must define if valid value is dict or list
self.valid_value_types = (list, dict)
self.value_on_not_set = {}
is_list = self.schema_data.get("is_list", False)
if is_list:
valid_value_types = (list, )
value_on_not_set = []
else:
valid_value_types = (dict, )
value_on_not_set = {}
self._is_list = is_list
self.valid_value_types = valid_value_types
self.value_on_not_set = value_on_not_set
self.default_metadata = {}
self.studio_override_metadata = {}
self.project_override_metadata = {}
@property
def is_list(self):
return self._is_list
@property
def is_dict(self):
return not self._is_list
def set(self, value):
self._validate_value_type(value)

View file

@ -235,13 +235,17 @@
### raw-json
- a little bit enhanced text input for raw json
- has validations of json format
- empty value is invalid value, always must be at least `{}` of `[]`
- empty value is invalid value, always must be json serializable
- valid value types are list `[]` and dictionary `{}`
- schema also defines valid value type
- by default it is dictionary
- to be able use list it is required to define `is_list` to `true`
```
{
"type": "raw-json",
"key": "profiles",
"label": "Extract Review profiles"
"label": "Extract Review profiles",
"is_list": true
}
```