From 1e8442ea88ebffbf0bf0ce9f967a60306d989b83 Mon Sep 17 00:00:00 2001 From: Paulo Costa Date: Wed, 19 Oct 2022 21:22:15 -0300 Subject: [PATCH] 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 --- openapi_python_client/__init__.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 44fc39cd4..3eeaa382c 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -104,6 +104,8 @@ def __init__( package_version=self.version, project_name=self.project_name, project_dir=self.project_dir, + openapi=self.openapi, + endpoint_collections_by_tag=self.openapi.endpoint_collections_by_tag, ) self.errors: List[GeneratorError] = [] @@ -264,18 +266,13 @@ def _build_api(self) -> None: client_path.write_text(client_template.render(), encoding=self.file_encoding) # Generate endpoints - endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag api_dir = self.package_dir / "api" api_dir.mkdir() api_init_path = api_dir / "__init__.py" api_init_template = self.env.get_template("api_init.py.jinja") - api_init_path.write_text( - api_init_template.render( - endpoint_collections_by_tag=endpoint_collections_by_tag, - ), - encoding=self.file_encoding, - ) + api_init_path.write_text(api_init_template.render(), encoding=self.file_encoding) + endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag endpoint_template = self.env.get_template( "endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"} )