Skip to content
Snippets Groups Projects
Commit c4461378 authored by Sebastian Böckelmann's avatar Sebastian Böckelmann
Browse files

Refactor generation of paramlist method

parent 8a81dd79
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@ import os
import re
import sys
from json import JSONEncoder
from pprint import pprint
import click
import yaml
......@@ -336,21 +337,30 @@ def typescript(output_dir):
return api_code
def generate_param_list(api_function: ApiFunction) -> str:
paramlist_signature = "\t" + api_function.name + "ParamsList(): ParamList {\n"
paramlist_return_statement = "\t\treturn {\n"
paramlist_old = "\t\t\t 'old': [$],\n"
paramlist_new = "\t\t\t 'new': [$]\n"
for function_parameter in api_function.parameters.items():
if function_parameter[1].old is not None:
paramlist_old = paramlist_old.replace('$', '\''+ function_parameter[1].name +'\', $')
if function_parameter[1].new is not None:
paramlist_new = paramlist_new.replace('$', '\'' + function_parameter[1].name + '\', $')
paramlist_old = paramlist_old.replace(', $', '')
paramlist_old = paramlist_old.replace('$', '')
paramlist_new = paramlist_new.replace(', $', '')
paramlist_new = paramlist_new.replace('$', '')
paramlist_return_statement += paramlist_old + paramlist_new + "\t\t}"
return paramlist_signature + paramlist_return_statement + "\n\t}"
code_template = ("\t$METHOD_NAMEParamList(): ParamList {\n"
"\t\treturn {\n"
"\t\t\t'old': [$OLD],\n"
"\t\t\t'new': [$NEW],\n"
"\t\t}\n"
"\t}")
code_template = code_template.replace("$METHOD_NAME", api_function.name)
for index, parameter in enumerate(api_function.parameters.values()):
replace_string = "'" + parameter.name + "'"
if parameter.old is not None:
if index < len(api_function.parameters) - 1:
replace_string += ", $OLD"
code_template = code_template.replace("$OLD", replace_string)
if parameter.new is not None:
if index < len(api_function.parameters) - 1:
replace_string += ", $NEW"
code_template = code_template.replace("$NEW", replace_string)
# Cleanup to remove unused $OLD or $NEW
code_template = code_template.replace('$OLD', '')
code_template = code_template.replace('$NEW', '')
return code_template
param_list_function = generate_param_list(api_function)
api_function_code = generate_api_call(api_function)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment