1616from .common import HTTPLibrary
1717from .common import library_config_dict
1818from .language_converters .python .generator import generator
19- from .language_converters .python .jinja_config import JINJA_ENV
2019from .language_converters .python .jinja_config import SERVICE_TEMPLATE
20+ from .language_converters .python .jinja_config import create_jinja_env
2121from .models import ConversionResult
2222
2323
@@ -109,13 +109,14 @@ def write_data(data: ConversionResult, output: Union[str, Path]) -> None:
109109 files = []
110110
111111 # Write the services.
112+ jinja_env = create_jinja_env ()
112113 for service in data .services :
113114 if len (service .operations ) == 0 :
114115 continue
115116 files .append (service .file_name )
116117 write_code (
117118 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 ()),
119120 )
120121
121122 # Create services.__init__.py file containing imports to all services.
@@ -137,13 +138,20 @@ def generate_data(
137138 library : Optional [HTTPLibrary ] = HTTPLibrary .httpx ,
138139 env_token_name : Optional [str ] = None ,
139140 use_orjson : bool = False ,
141+ custom_template_path : Optional [str ] = None ,
140142) -> None :
141143 """
142144 Generate Python code from an OpenAPI 3.0 specification.
143145 """
144146 data = get_open_api (source )
145147 click .echo (f"Generating data from { source } " )
146148
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+ )
148156
149157 write_data (result , output )
0 commit comments