Skip to content

Commit 437942b

Browse files
committed
update generate script per comments
1 parent ded6680 commit 437942b

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

yaml/scripts/generate_yaml_java_templates.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,19 @@
2222
import yaml
2323
import textwrap
2424

25-
26-
def get_java_type(param_type):
27-
"""Maps a YAML parameter type to a Java type."""
28-
if param_type == 'text':
29-
return 'String'
30-
elif param_type == 'integer':
31-
return 'Integer'
32-
elif param_type == 'boolean':
33-
return 'Boolean'
34-
else:
35-
return 'String'
36-
37-
def get_template_parameter_type(param_type):
38-
"""Maps a YAML parameter type to a TemplateParameter annotation type."""
39-
if param_type == 'text':
40-
return 'TemplateParameter.Text'
41-
elif param_type == 'integer':
42-
return 'TemplateParameter.Integer'
43-
elif param_type == 'boolean':
44-
return 'TemplateParameter.Boolean'
45-
else:
46-
return 'TemplateParameter.Text'
25+
JAVA_TYPE_BY_YAML_TYPE = {
26+
'text': 'String',
27+
'integer': 'Integer',
28+
'boolean': 'Boolean',
29+
'double' : 'Double'
30+
}
31+
32+
TEMPLATE_TYPE_BY_YAML_TYPE = {
33+
'text': 'TemplateParameter.Text',
34+
'integer': 'TemplateParameter.Integer',
35+
'boolean': 'TemplateParameter.Boolean',
36+
'double' : 'TemplateParameter.Double'
37+
}
4738

4839
def get_git_root():
4940
"""Gets the root directory of the git repository."""
@@ -102,8 +93,8 @@ def generate_java_interface(yaml_path, java_path):
10293
parameters_code = []
10394
for i, param in enumerate(parameters):
10495
param_name = param['name']
105-
java_type = get_java_type(param.get('type', 'text'))
106-
template_param_type = get_template_parameter_type(param.get('type', 'text'))
96+
java_type = JAVA_TYPE_BY_YAML_TYPE.get(param.get('type', 'text'), 'String')
97+
template_param_type = TEMPLATE_TYPE_BY_YAML_TYPE.get(param.get('type', 'text'))
10798
getter_name = "get" + param_name[0].upper() + param_name[1:]
10899
wrapped_description = param.get('description', '').strip()
109100
wrapped_help_text = param.get('help', '').strip()
@@ -127,10 +118,8 @@ def generate_java_interface(yaml_path, java_path):
127118
if 'default' in param:
128119
if java_type == 'String':
129120
param_code += f' @Default.String("{param["default"]}")\n'
130-
elif java_type == 'Integer':
131-
param_code += f' @Default.Integer({param["default"]})\n'
132-
elif java_type == 'Boolean':
133-
param_code += f' @Default.Boolean({param["default"]})\n'
121+
else:
122+
param_code += f" @Default.{java_type}({param['default']})\n"
134123

135124
# getter name
136125
param_code += f" {java_type} {getter_name}();"

0 commit comments

Comments
 (0)