16
16
from .common import HTTPLibrary
17
17
from .common import library_config_dict
18
18
from .language_converters .python .generator import generator
19
- from .language_converters .python .jinja_config import JINJA_ENV
20
19
from .language_converters .python .jinja_config import SERVICE_TEMPLATE
20
+ from .language_converters .python .jinja_config import create_jinja_env
21
21
from .models import ConversionResult
22
22
23
23
@@ -109,13 +109,14 @@ def write_data(data: ConversionResult, output: Union[str, Path]) -> None:
109
109
files = []
110
110
111
111
# Write the services.
112
+ jinja_env = create_jinja_env ()
112
113
for service in data .services :
113
114
if len (service .operations ) == 0 :
114
115
continue
115
116
files .append (service .file_name )
116
117
write_code (
117
118
services_path / f"{ service .file_name } .py" ,
118
- JINJA_ENV .get_template (SERVICE_TEMPLATE ).render (** service .dict ()),
119
+ jinja_env .get_template (SERVICE_TEMPLATE ).render (** service .dict ()),
119
120
)
120
121
121
122
# Create services.__init__.py file containing imports to all services.
@@ -137,13 +138,20 @@ def generate_data(
137
138
library : Optional [HTTPLibrary ] = HTTPLibrary .httpx ,
138
139
env_token_name : Optional [str ] = None ,
139
140
use_orjson : bool = False ,
141
+ custom_template_path : Optional [str ] = None ,
140
142
) -> None :
141
143
"""
142
144
Generate Python code from an OpenAPI 3.0 specification.
143
145
"""
144
146
data = get_open_api (source )
145
147
click .echo (f"Generating data from { source } " )
146
148
147
- result = generator (data , library_config_dict [library ], env_token_name , use_orjson )
149
+ result = generator (
150
+ data ,
151
+ library_config_dict [library ],
152
+ env_token_name ,
153
+ use_orjson ,
154
+ custom_template_path ,
155
+ )
148
156
149
157
write_data (result , output )
0 commit comments