Skip to content

Commit 82bcbb1

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

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

openapi_python_client/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(
9595

9696
self.env.filters.update(TEMPLATE_FILTERS)
9797
self.env.globals.update(
98+
config=self.config,
9899
utils=utils,
99100
python_identifier=lambda x: utils.PythonIdentifier(x, config.field_prefix),
100101
class_name=lambda x: utils.ClassName(x, config.field_prefix),
@@ -104,6 +105,8 @@ def __init__(
104105
package_version=self.version,
105106
project_name=self.project_name,
106107
project_dir=self.project_dir,
108+
openapi=self.openapi,
109+
endpoint_collections_by_tag=self.openapi.endpoint_collections_by_tag,
107110
)
108111
self.errors: List[GeneratorError] = []
109112

@@ -264,18 +267,13 @@ def _build_api(self) -> None:
264267
client_path.write_text(client_template.render(), encoding=self.file_encoding)
265268

266269
# Generate endpoints
267-
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag
268270
api_dir = self.package_dir / "api"
269271
api_dir.mkdir()
270272
api_init_path = api_dir / "__init__.py"
271273
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-
)
274+
api_init_path.write_text(api_init_template.render(), encoding=self.file_encoding)
278275

276+
endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag
279277
endpoint_template = self.env.get_template(
280278
"endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"}
281279
)

0 commit comments

Comments
 (0)