Skip to content

Commit 1e8442e

Browse files
committed
Add endpoint_collections_by_tag and openapi to the templating globals
This makes `endpoint_collections_by_tag` available in every template (Instead of only a few selected places). `openapi` is not obviously useful, but is being used on my custom templates
1 parent 47e576c commit 1e8442e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

openapi_python_client/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def __init__(
104104
package_version=self.version,
105105
project_name=self.project_name,
106106
project_dir=self.project_dir,
107+
openapi=self.openapi,
108+
endpoint_collections_by_tag=self.openapi.endpoint_collections_by_tag,
107109
)
108110
self.errors: List[GeneratorError] = []
109111

@@ -264,18 +266,13 @@ def _build_api(self) -> None:
264266
client_path.write_text(client_template.render(), encoding=self.file_encoding)
265267

266268
# Generate endpoints
267-
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag
268269
api_dir = self.package_dir / "api"
269270
api_dir.mkdir()
270271
api_init_path = api_dir / "__init__.py"
271272
api_init_template = self.env.get_template("api_init.py.jinja")
272-
api_init_path.write_text(
273-
api_init_template.render(
274-
endpoint_collections_by_tag=endpoint_collections_by_tag,
275-
),
276-
encoding=self.file_encoding,
277-
)
273+
api_init_path.write_text(api_init_template.render(), encoding=self.file_encoding)
278274

275+
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag
279276
endpoint_template = self.env.get_template(
280277
"endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"}
281278
)

0 commit comments

Comments
 (0)