summaryrefslogtreecommitdiff
path: root/generator
diff options
context:
space:
mode:
authorShinichi Watanabe <swatanabe@xevo.com>2021-01-18 19:11:49 +0900
committerShinichi Watanabe <swatanabe@xevo.com>2021-01-18 19:11:49 +0900
commit760f674634c93273e68680dbc8baae152c709714 (patch)
tree9d796a78466ab76760ebd6e3af8f790a3a3743fd /generator
parentf4938b994ac0a8e4857d838e572696e23c5039ad (diff)
parent18dfd8ae8d239eef2f6984a23cd4f137e1465c55 (diff)
downloadsdl_ios-760f674634c93273e68680dbc8baae152c709714.tar.gz
Merge remote-tracking branch 'upstream/develop' into feature/issue-1553
Diffstat (limited to 'generator')
-rw-r--r--generator/transformers/common_producer.py37
1 files changed, 31 insertions, 6 deletions
diff --git a/generator/transformers/common_producer.py b/generator/transformers/common_producer.py
index 977cc2232..3a591a05d 100644
--- a/generator/transformers/common_producer.py
+++ b/generator/transformers/common_producer.py
@@ -365,19 +365,27 @@ class InterfaceProducerCommon(ABC):
'deprecated': json.loads(param.deprecated.lower()) if param.deprecated else False,
'modifier': 'strong',
'history': param.history}
+
+ parameterItems = OrderedDict()
if isinstance(param.param_type, (Integer, Float, String, Array)):
- data['description'].append(self.create_param_descriptor(param.param_type, OrderedDict()))
+ self.create_param_type_descriptor(param.param_type, parameterItems)
+
+ if isinstance(param.param_type, (Boolean, Enum)):
+ self.create_param_default_value_descriptor(param, parameterItems)
+
+ if len(parameterItems) > 0:
+ data['description'].append(json.dumps(parameterItems, sort_keys=False))
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_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
+ Gets all the descriptors for a parameter to be used in parameter's documentation (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
+ :return: All the descriptor params
"""
# The key is a descriptor (i.e. max_value) and value is the associated value (i.e. 100). Some values will be dictionaries that have to be parsed to get additional descriptors (e.g. the value for an array of strings' data type will be sub-dictionary describing the min_length, max_length, and default value for the strings used in the array)
for key, value in param_type.__dict__.items():
@@ -387,7 +395,7 @@ 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_type_descriptor(value, parameterItems)
else:
if 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
@@ -396,7 +404,24 @@ class InterfaceProducerCommon(ABC):
parameterDescriptor = self.update_param_descriptor(key)
parameterItems[parameterDescriptor] = value
- return json.dumps(parameterItems, sort_keys=False)
+ return parameterItems
+
+ def create_param_default_value_descriptor(self, param, parameterItems):
+ """
+ Extracts the default value for a parameter to be used in parameter's documentation (HAX: The default_value for Ints and Floats is save to both the param and param_type but is only saved to the param_type for Enums and Bools for some reason)
+ :param param: param from the initial Model
+ :param parameterItems: Ordered dictionary that stores each of the parameter's descriptors
+ :return: All the descriptor params
+ """
+ if param.default_value is None:
+ return parameterItems
+
+ if isinstance(param.param_type, Enum):
+ parameterItems['default_value'] = param.default_value.name
+ else:
+ parameterItems['default_value'] = param.default_value
+
+ return parameterItems
def update_param_descriptor(self, parameterName):
"""