Skip to content

Commit

Permalink
Merge pull request #1917 from smartdevicelink/bugfix/generator/issue_…
Browse files Browse the repository at this point in the history
…1905_rpc_param_names_for_structs

RPC spec generator no longer generates unused SDLRPCParameterNames
  • Loading branch information
joeljfischer authored Feb 23, 2021
2 parents fb30f8b + 9a93e69 commit ac0f68a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 3 additions & 5 deletions generator/test/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_process_function_name(self):
structs = {
'SoftButton': Struct(name='SoftButton', members={
'image': Param(name='image', param_type=String(), since='1.0.0', description=['image description']),
'ignore': Param(name='ignore', param_type=Struct(name='ignore'))}),
'dayColorScheme': Param(name='dayColorScheme', param_type=Struct(name='TemplateColorScheme', description=[
'\nA color scheme for all display layout templates.\n']))}),
'PresetBankCapabilities': Struct(name='PresetBankCapabilities', members={
'availableHdChannelsAvailable': Param(name='availableHdChannelsAvailable', param_type=Boolean(),
since='2.0.0',
Expand All @@ -89,11 +90,8 @@ def test_process_function_name(self):
self.producer.common_names(description=['availableHDChannelsAvailable description'],
since='2.0.0', name='AvailableHdChannelsAvailable',
origin='availableHdChannelsAvailable'),
self.producer.common_names(description=[], name='Ignore', origin='ignore', since=None),
self.producer.common_names(description=[], name='DayColorScheme', origin='dayColorScheme', since=None),
self.producer.common_names(description=['image description'], name='Image', origin='image', since='1.0.0'),
self.producer.common_names(description=[], name='PresetBankCapabilities', origin='PresetBankCapabilities',
since=None),
self.producer.common_names(description=[], name='SoftButton', origin='SoftButton', since=None),
self.producer.common_names(description=['syncMsgVersion description'], name='SdlMsgVersion',
origin='syncMsgVersion', since='3.5.0')]
actual = self.producer.get_simple_params(functions, structs)
Expand Down
6 changes: 2 additions & 4 deletions generator/transformers/functions_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ def evaluate(self, element) -> dict:
"""
origin = element.name
name = self._replace_sync(element.name)
# if isinstance(element.param_type, (Integer, Float, Boolean, String)):
return {name: self.common_names(**{
'name': self.title(name),
'origin': origin,
'description': self.extract_description(element.description),
'since': element.since})}
# return OrderedDict()

def get_simple_params(self, functions: dict, structs: dict) -> dict:
"""
Standalone method used for preparing SDLRPCParameterNames collection ready to be applied to Jinja2 template
Creates a list of all parameter names used in functions and structs. This list is used by a Jinja2 template to generate the SDLRPCParameterNames class.
:param functions: collection with all functions from initial Model
:param structs: collection with all structs from initial Model
:return: collection with transformed element ready to be applied to Jinja2 template
Expand All @@ -110,8 +108,8 @@ def get_simple_params(self, functions: dict, structs: dict) -> dict:
render.update(self.evaluate(param))

for struct in structs.values():
render.update(self.evaluate(struct))
for param in struct.members.values():
render.update(self.evaluate(param))

unique = dict(zip(list(map(lambda l: l.name, render.values())), render.values()))
return {'params': sorted(unique.values(), key=lambda a: a.name)}

0 comments on commit ac0f68a

Please sign in to comment.