Skip to content

Commit cdd304c

Browse files
committed
endoint __init__ template / factorize propagated vars
1 parent b541e01 commit cdd304c

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Diff for: end_to_end_tests/test_custom_templates/api_init.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
""" Contains methods for accessing the API """
22

33
from typing import Type
4-
{% for tag, collection in endpoint_collections_by_tag %}
4+
{% for tag in endpoint_collections_by_tag.keys() %}
55
from {{ package_name }}.api.{{ tag }} import {{ utils.pascal_case(tag) }}Endpoints
66
{% endfor %}
77

88
class {{ utils.pascal_case(package_name) }}Api:
9-
{% for tag, collection in endpoint_collections_by_tag %}
9+
{% for tag in endpoint_collections_by_tag.keys() %}
1010
@classmethod
1111
def {{ tag }}(cls) -> Type[{{ utils.pascal_case(tag) }}Endpoints]:
1212
return {{ utils.pascal_case(tag) }}Endpoints

Diff for: end_to_end_tests/test_custom_templates/endpoint_init.py.jinja

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
""" Contains methods for accessing the API Endpoints """
22

33
import types
4-
{% for endpoint in endpoints %}
5-
from {{ package_name }}.api.{{ tag }} import {{ utils.snake_case(endpoint.name) }}
4+
{% for endpoint in endpoint_collection.endpoints %}
5+
from {{ package_name }}.api.{{ endpoint_collection.tag }} import {{ utils.snake_case(endpoint.name) }}
66
{% endfor %}
77

8-
class {{ utils.pascal_case(tag) }}Endpoints:
8+
class {{ utils.pascal_case(endpoint_collection.tag) }}Endpoints:
99

10-
{% for endpoint in endpoints %}
10+
{% for endpoint in endpoint_collection.endpoints %}
1111

1212
@classmethod
1313
def {{ utils.snake_case(endpoint.name) }}(cls) -> types.ModuleType:

Diff for: openapi_python_client/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _build_api(self) -> None:
240240
client_path.write_text(client_template.render(), encoding=self.file_encoding)
241241

242242
# Generate endpoints
243-
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag.items()
243+
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag
244244
api_dir = self.package_dir / "api"
245245
api_dir.mkdir()
246246
api_init_path = api_dir / "__init__.py"
@@ -254,14 +254,14 @@ def _build_api(self) -> None:
254254
)
255255

256256
endpoint_template = self.env.get_template("endpoint_module.py.jinja")
257-
for tag, collection in endpoint_collections_by_tag:
257+
for tag, collection in endpoint_collections_by_tag.items():
258258
tag_dir = api_dir / tag
259259
tag_dir.mkdir()
260260

261261
endpoint_init_path = tag_dir / "__init__.py"
262262
endpoint_init_template = self.env.get_template("endpoint_init.py.jinja")
263263
endpoint_init_path.write_text(
264-
endpoint_init_template.render(package_name=self.package_name, tag=tag, endpoints=collection.endpoints),
264+
endpoint_init_template.render(package_name=self.package_name, endpoint_collection=collection),
265265
encoding=self.file_encoding,
266266
)
267267
(tag_dir / "__init__.py").touch()

0 commit comments

Comments
 (0)