Skip to content

Commit 8be06af

Browse files
author
Joel Collins
committed
Default dictionary keys as not required
1 parent 203b887 commit 8be06af

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

labthings/server/types/properties.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@
1010

1111

1212
class PropertyConverter:
13-
def __init__(self):
13+
def __init__(self, required=True, allow_none=False):
1414
self._registry = TypeRegistry()
1515
self._registry.register(List, self._list_converter)
1616
self._registry.register(list, self._list_converter)
1717

18+
self._required = required
19+
self._allow_none = allow_none
20+
1821
def _list_converter(self, subtypes: Tuple[type], **opts) -> FieldABC:
1922
return fields.List(subtypes[0], **opts)
2023

2124
def convert(self, value, **kwargs) -> FieldABC:
22-
# sane defaults
23-
allow_none = False
24-
required = True
25+
allow_none = self._allow_none
26+
required = self._required
2527
example = value
2628

2729
# set this after optional check
@@ -49,7 +51,7 @@ def data_dict_to_schema(data_dict: dict):
4951
Returns:
5052
dict: Dictionary of Marshmallow fields matching input data types
5153
"""
52-
converter = PropertyConverter()
54+
converter = PropertyConverter(required=False)
5355

5456
working_dict = copy.deepcopy(data_dict)
5557

0 commit comments

Comments
 (0)