Skip to content

Commit 9bf8610

Browse files
committed
python: Update api_resource template to support sub-resources
1 parent 7e84604 commit 9bf8610

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

python/templates/api_resource.py.jinja

+18-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ from .. import models
1111

1212
{% for c in referenced_components -%}
1313
from ..models import {{ c | to_upper_camel_case }}
14+
{% endfor -%}
15+
{% for _, sub in resource.subresources | items -%}
16+
from .{{ sub.name | to_snake_case }} import (
17+
{{ sub.name | to_upper_camel_case }},
18+
{{ sub.name | to_upper_camel_case }}Async,
19+
)
1420
{% endfor %}
1521

1622

@@ -65,7 +71,15 @@ class {{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options(BaseOpt
6571

6672
{% for is_async in [true, false] %}
6773
class {{ resource.name | to_upper_camel_case }}{% if is_async %}Async{% endif %}(ApiBase):
68-
{%- if resource.operations | length != 0 %}
74+
{%- for name, sub in resource.subresources | items %}
75+
{%- set sub_type_name %}{{ sub.name | to_upper_camel_case }}{% if is_async %}Async{% endif %}{% endset %}
76+
@property
77+
def {{ name | to_snake_case }}(self) -> {{ sub_type_name }}:
78+
return {{ sub_type_name }}(self._client)
79+
80+
{% endfor %}
81+
82+
{%- if resource.operations | length > 0 %}
6983
{%- for op in resource.operations %}
7084
{% if op.response_body_schema_name is defined -%}
7185
{% set return_type = op.response_body_schema_name | to_upper_camel_case -%}
@@ -142,8 +156,9 @@ class {{ resource.name | to_upper_camel_case }}{% if is_async %}Async{% endif %}
142156

143157
{{ code | indent(4, true) }}
144158
{% endfor -%}
145-
{% else %}
146-
{# empty class with no functions, so we have a pass here #}
159+
{% endif %}
160+
{% if resource.subresources | length == 0 and resource.operations | length == 0 %}
161+
{# empty class with no members, so we have a pass here -#}
147162
pass
148163
{% endif %}
149164
{% endfor %}

0 commit comments

Comments
 (0)