diff options
author | Frank Elias <francois.elias@livio.io> | 2020-10-21 15:41:46 -0400 |
---|---|---|
committer | Frank Elias <francois.elias@livio.io> | 2020-10-21 15:41:46 -0400 |
commit | 3bdf221c15110e187307dcacb7777316e8b35bb7 (patch) | |
tree | ad218961f9264f8459d531a8a551121a4f13c496 | |
parent | e65236b004893227270cef02c09278c1f42f93af (diff) | |
download | sdl_ios-3bdf221c15110e187307dcacb7777316e8b35bb7.tar.gz |
Enum's default value
Add missing default value for enum types
-rw-r--r-- | generator/transformers/common_producer.py | 22 | ||||
-rw-r--r-- | generator/transformers/enums_producer.py | 8 |
2 files changed, 26 insertions, 4 deletions
diff --git a/generator/transformers/common_producer.py b/generator/transformers/common_producer.py index 63a7134bb..c31fe35f8 100644 --- a/generator/transformers/common_producer.py +++ b/generator/transformers/common_producer.py @@ -205,6 +205,7 @@ class InterfaceProducerCommon(ABC): :param item: named tuple with initiator (constructor) parameter :return: wrapped parameter """ + # print('Item: ' + str(item)) if re.match(r'\w*Int\d+|BOOL|float|double', item.type_native) or \ any(map(lambda n: item.type_native.lower() in n.lower(), self.struct_names)): return '@({})'.format(item.constructor_argument) @@ -358,21 +359,31 @@ class InterfaceProducerCommon(ABC): :return: self.param_named with prepared params """ param.name = self.replace_keywords(param.name) + # print('Default value is: ' + str(param.default_value)) + if isinstance(param.param_type, (Enum)) and param.default_value: + print('Default value is: ' + str(param.default_value.name)) + print('Default value is: ' + str(param.default_value.internal_name)) + print('Name is: ', str(param.name)) + data = {'constructor_argument_override': None, 'description': self.extract_description(param.description), 'since': param.since, 'mandatory': param.is_mandatory, 'deprecated': json.loads(param.deprecated.lower()) if param.deprecated else False, 'modifier': 'strong', + # 'default_value': param.default_value, 'history' : param.history } if isinstance(param.param_type, (Integer, Float, String, Array)): - data['description'].append(self.create_param_descriptor(param.param_type, OrderedDict())) + data['description'].append(self.create_param_descriptor(param.param_type, OrderedDict(), param.name)) + + if isinstance(param.param_type, (Enum)) and param.default_value: + data['description'].append(param.default_value.value) data.update(self.extract_type(param)) data.update(self.param_origin_change(param.name)) return self.param_named(**data) - def create_param_descriptor(self, param_type, parameterItems): + def create_param_descriptor(self, param_type, parameterItems, paramName): """ 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 :param param_type: param_type from the initial Model @@ -387,9 +398,12 @@ class InterfaceProducerCommon(ABC): # Skip adding documentation for the data type if it is a struct or enum. This is unnecessary as each enum or struct has its own documentation continue else: - self.create_param_descriptor(value, parameterItems) + self.create_param_descriptor(value, parameterItems, paramName) else: - if key == 'default_value' and value is None: + if key == 'default_value' and paramName == 'systemAction': + parameterDescriptor = self.update_param_descriptor(key) + parameterItems[parameterDescriptor] = value + elif key == 'default_value' and value is None: # Do not add the default_value key/value pair unless it has been explicitly set in the RPC Spec continue else: diff --git a/generator/transformers/enums_producer.py b/generator/transformers/enums_producer.py index 748f6cbe6..c8288ed59 100644 --- a/generator/transformers/enums_producer.py +++ b/generator/transformers/enums_producer.py @@ -60,6 +60,7 @@ class EnumsProducer(InterfaceProducerCommon): 'description': self.extract_description(param.description), 'since': param.since, 'history': param.history, + # 'default_value': param.default_value, 'deprecated': json.loads(param.deprecated.lower()) if param.deprecated else False} name = None if re.match(r'^[A-Z]{1,2}\d|\d[A-Z]{1,2}$', param.name): @@ -80,4 +81,11 @@ class EnumsProducer(InterfaceProducerCommon): if any(re.search(r'^(sdl)?({}){}$'.format(item_name.casefold(), name.casefold()), k) for k in self.key_words): name = self._replace_keywords(name) data['name'] = name + # try: + # param.default_value + # except NameError: + # data['default_value'] = None + # else: + # data['default_value'] = param.default_value + return self.param_named(**data) |