|
1 | 1 | {% macro add_lookup(property) %} |
2 | | - {% set lookup_endpoint = lookup_parameters.get(property.name) %} |
3 | | - {% set lookup_entity = lookup_endpoint.data["x-cli-entity"] if lookup_endpoint %} |
4 | | - {% set lookup_type = property.get_instance_type_string() %} |
5 | | - {% if lookup_type == 'list' %} |
6 | | - {% set lookup_type = property.inner_property.get_instance_type_string() %} |
7 | | - {% endif %} |
8 | | - {% if lookup_endpoint -%} |
| 2 | + {% set lookup_endpoint = lookup_parameters.get(property.name) %} |
| 3 | + {% set lookup_entity = lookup_endpoint.data["x-cli-entity"] if lookup_endpoint %} |
| 4 | + {% set lookup_type = property.get_instance_type_string() %} |
| 5 | + {% if lookup_type == 'list' %} |
| 6 | + {% set lookup_type = property.inner_property.get_instance_type_string() %} |
| 7 | + {% endif %} |
| 8 | + {% if lookup_endpoint -%} |
9 | 9 | def {{ lookup_function(property, lookup_entity.id) }}(ref: str) -> Union[None, {{ lookup_type }}]: |
10 | 10 | return api_{{ python_identifier(lookup_endpoint.name) }}.Command(self._context).lookup(ref) |
11 | 11 |
|
12 | | - {% endif %} |
| 12 | + {% endif %} |
13 | 13 | {% endmacro %} |
14 | 14 |
|
15 | 15 | {% macro add_primitive(property, argument) %} |
|
74 | 74 |
|
75 | 75 | {% macro lookup_function(property, entity_id) %} |
76 | 76 | {% filter trim %} |
77 | | -{% set suffix = "_" + entity_id %} |
78 | | -{# Normalize property.python_name of "server"/"server_id"/"server_ids" to "server_id" #} |
79 | | -lookup_{{ property.python_name.removesuffix(suffix+"s").removesuffix(suffix) }}{{ suffix }} |
| 77 | + {% set suffix = "_" + entity_id %} |
| 78 | + {# Normalize property.python_name of "server"/"server_id"/"server_ids" to "server_id" #} |
| 79 | + lookup_{{ property.python_name.removesuffix(suffix+"s").removesuffix(suffix) }}{{ suffix }} |
80 | 80 | {% endfilter %} |
81 | 81 | {% endmacro %} |
82 | 82 |
|
83 | 83 | {% macro remove_suffix(value, suffix) %} |
84 | 84 | {% filter trim %} |
85 | | -{% if value.endswith(suffix + "s") %} |
86 | | -{{ value.removesuffix(suffix + "s") }}s |
87 | | -{% elif value.endswith(suffix) %} |
88 | | -{{ value.removesuffix(suffix) }} |
89 | | -{% else %} |
90 | | -{{ value }} |
91 | | -{% endif %} |
| 85 | + {% if value.endswith(suffix + "s") %} |
| 86 | + {{ value.removesuffix(suffix + "s") }}s |
| 87 | + {% elif value.endswith(suffix) %} |
| 88 | + {{ value.removesuffix(suffix) }} |
| 89 | + {% else %} |
| 90 | + {{ value }} |
| 91 | + {% endif %} |
92 | 92 | {% endfilter %} |
93 | 93 | {% endmacro %} |
0 commit comments