summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2020-10-27 12:15:10 -0400
committerNicoleYarroch <nicole@livio.io>2020-10-27 12:15:10 -0400
commit31733ea6c54238da12bd82fded94b0b5fa0a2f9a (patch)
tree8b9345f54f47d5003f4cf69d8d57ec7571c2a73e
parentafa78533c7d044fb7997e913ac5b16d392a9eb1d (diff)
downloadsdl_ios-31733ea6c54238da12bd82fded94b0b5fa0a2f9a.tar.gz
Added method to get default value
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--generator/transformers/common_producer.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/generator/transformers/common_producer.py b/generator/transformers/common_producer.py
index 376df7e27..2cffbd5a2 100644
--- a/generator/transformers/common_producer.py
+++ b/generator/transformers/common_producer.py
@@ -368,20 +368,37 @@ class InterfaceProducerCommon(ABC):
if isinstance(param.param_type, (Integer, Float, String, Array)):
data['description'].append(self.create_param_type_descriptor(param.param_type, OrderedDict()))
- if isinstance(param.param_type, (Enum)) and param.default_value:
- print('\nEnum default value whoo ' + param.default_value.name)
- for key, value in param.__dict__.items():
- print('key ' + key + ', value ' + str(value))
- for key, value in param.param_type.__dict__.items():
- print('\tparam_type key ' + key + ', value ' + str(value))
+ if isinstance(param.param_type, (Integer, Float, Boolean, Enum)):
+ param_descriptor = self.create_param_default_value_descriptor(param, OrderedDict())
+ if param_descriptor:
+ data['description'].append(param_descriptor)
data.update(self.extract_type(param))
data.update(self.param_origin_change(param.name))
return self.param_named(**data)
+ def create_param_default_value_descriptor(self, param, parameterItems):
+ """
+ Creates a documentation string of the default value for a parameter.
+ :param param: param from the initial Model
+ :param parameterItems: Ordered dictionary that stores each of the parameter's descriptors
+ :return: All the descriptor params from param_type concatenated into one string
+ """
+ if param.default_value is None:
+ return ""
+
+ if isinstance(param.param_type, Enum):
+ print('adding Enum default_value ' + str(param.default_value) + ' for: ' + param.name)
+ parameterItems['default_value'] = param.default_value.name
+ else:
+ print('adding Non-Enum default_value ' + str(param.default_value) + ' for: ' + param.name)
+ parameterItems['default_value'] = param.default_value
+
+ return json.dumps(parameterItems, sort_keys=False)
+
def create_param_type_descriptor(self, param_type, parameterItems):
"""
- Recursively creates a documentation string of all the descriptors for a parameter (e.g. {"string_min_length": 1, string_max_length": 500}). The parameters should be returned in the same order they were added to the parameterItems dictionary
+ Recursively creates a documentation string of all the descriptors for a parameter type (e.g. {"string_min_length": 1, string_max_length": 500}). The parameters should be returned in the same order they were added to the parameterItems dictionary
:param param_type: param_type from the initial Model
:param parameterItems: Ordered dictionary that stores each of the parameter's descriptors
:return: All the descriptor params from param_type concatenated into one string