@@ -224,18 +224,34 @@ def process_from_openapi(
224224
225225 for spec in specs :
226226 if subcommand == "to_sdk" :
227+ from openapi_client .classes .emit import emit_models_module
228+
227229 generator = ClientGenerator (spec )
228230 (out_dir / "client.py" ).write_text (
229231 generator .generate_code (), encoding = "utf-8"
230232 )
233+
234+ if spec .components and getattr (spec .components , "schemas" , None ):
235+ (out_dir / "models.py" ).write_text (
236+ emit_models_module (spec .components .schemas ), encoding = "utf-8"
237+ )
238+
231239 (out_dir / "test_client.py" ).write_text (
232240 emit_tests (spec ).code , encoding = "utf-8"
233241 )
234242 elif subcommand == "to_sdk_cli" :
243+ from openapi_client .classes .emit import emit_models_module
244+
235245 generator = ClientGenerator (spec )
236246 (out_dir / "client.py" ).write_text (
237247 generator .generate_code (), encoding = "utf-8"
238248 )
249+
250+ if spec .components and getattr (spec .components , "schemas" , None ):
251+ (out_dir / "models.py" ).write_text (
252+ emit_models_module (spec .components .schemas ), encoding = "utf-8"
253+ )
254+
239255 from openapi_client .cli_sdk_cdd .emit import emit_cli_sdk
240256
241257 (out_dir / "cli_main.py" ).write_text (emit_cli_sdk (spec ), encoding = "utf-8" )
@@ -279,6 +295,7 @@ def sync_to_openapi(input_path: str, output_path: str) -> None:
279295 ) # type: ignore
280296
281297 client_py = in_path / "client.py"
298+ models_py = in_path / "models.py"
282299 mock_py = in_path / "mock_server.py"
283300 test_py = in_path / "test_client.py"
284301 cli_py = in_path / "cli_main.py"
@@ -291,6 +308,11 @@ def sync_to_openapi(input_path: str, output_path: str) -> None:
291308 extract_classes_from_ast (mod , spec )
292309 extract_functions_from_ast (mod , spec )
293310
311+ if models_py .exists ():
312+ from openapi_client .classes .parse import extract_classes_from_ast
313+ mod = cst .parse_module (models_py .read_text (encoding = "utf-8" ))
314+ extract_classes_from_ast (mod , spec )
315+
294316 if mock_py .exists ():
295317 mod = cst .parse_module (mock_py .read_text (encoding = "utf-8" ))
296318 extract_mocks_from_ast (mod , spec )
@@ -333,6 +355,7 @@ def sync_dir(project_dir: str) -> None:
333355 d = Path (project_dir )
334356
335357 client_py = d / "client.py"
358+ models_py = d / "models.py"
336359 mock_py = d / "mock_server.py"
337360 test_py = d / "test_client.py"
338361 cli_py = d / "cli_main.py"
@@ -355,6 +378,11 @@ def sync_dir(project_dir: str) -> None:
355378 extract_classes_from_ast (mod , spec )
356379 extract_functions_from_ast (mod , spec )
357380
381+ if models_py .exists ():
382+ from openapi_client .classes .parse import extract_classes_from_ast
383+ mod = cst .parse_module (models_py .read_text (encoding = "utf-8" ))
384+ extract_classes_from_ast (mod , spec )
385+
358386 if mock_py .exists ():
359387 mod = cst .parse_module (mock_py .read_text (encoding = "utf-8" ))
360388 extract_mocks_from_ast (mod , spec )
@@ -378,6 +406,11 @@ def sync_dir(project_dir: str) -> None:
378406
379407 generator = ClientGenerator (spec )
380408 client_py .write_text (generator .generate_code (), encoding = "utf-8" )
409+
410+ if spec .components and getattr (spec .components , "schemas" , None ):
411+ from openapi_client .classes .emit import emit_models_module
412+ models_py .write_text (emit_models_module (spec .components .schemas ), encoding = "utf-8" )
413+
381414 test_py .write_text (emit_tests (spec ).code , encoding = "utf-8" )
382415 mock_py .write_text (emit_mock_server (spec ).code , encoding = "utf-8" )
383416 if cli_py .exists ():
0 commit comments