Skip to content

Commit 9bf6a97

Browse files
committed
Add an option to define an output path when generating or updating the client
1 parent 26e7e0f commit 9bf6a97

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

openapi_python_client/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def __init__(
5656
config: Config,
5757
custom_template_path: Optional[Path] = None,
5858
file_encoding: str = "utf-8",
59+
output_path: Optional[Path] = None,
5960
) -> None:
6061
self.openapi: GeneratorData = openapi
6162
self.meta: MetaType = meta
@@ -78,7 +79,7 @@ def __init__(
7879
)
7980

8081
self.project_name: str = config.project_name_override or f"{utils.kebab_case(openapi.title).lower()}-client"
81-
self.project_dir: Path = Path.cwd()
82+
self.project_dir: Path = Path.cwd() if output_path is None else Path(output_path).absolute()
8283
if meta != MetaType.NONE:
8384
self.project_dir /= self.project_name
8485

@@ -300,6 +301,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
300301
config: Config,
301302
custom_template_path: Optional[Path] = None,
302303
file_encoding: str = "utf-8",
304+
output_path: Optional[Path] = None,
303305
) -> Union[Project, GeneratorError]:
304306
data_dict = _get_document(url=url, path=path)
305307
if isinstance(data_dict, GeneratorError):
@@ -313,6 +315,7 @@ def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
313315
meta=meta,
314316
file_encoding=file_encoding,
315317
config=config,
318+
output_path=output_path
316319
)
317320

318321

@@ -324,6 +327,7 @@ def create_new_client(
324327
config: Config,
325328
custom_template_path: Optional[Path] = None,
326329
file_encoding: str = "utf-8",
330+
output_path: Optional[Path] = None,
327331
) -> Sequence[GeneratorError]:
328332
"""
329333
Generate the client library
@@ -338,6 +342,7 @@ def create_new_client(
338342
meta=meta,
339343
file_encoding=file_encoding,
340344
config=config,
345+
output_path=output_path
341346
)
342347
if isinstance(project, GeneratorError):
343348
return [project]
@@ -352,6 +357,7 @@ def update_existing_client(
352357
config: Config,
353358
custom_template_path: Optional[Path] = None,
354359
file_encoding: str = "utf-8",
360+
output_path: Optional[Path] = None,
355361
) -> Sequence[GeneratorError]:
356362
"""
357363
Update an existing client library
@@ -366,6 +372,7 @@ def update_existing_client(
366372
meta=meta,
367373
file_encoding=file_encoding,
368374
config=config,
375+
output_path=output_path
369376
)
370377
if isinstance(project, GeneratorError):
371378
return [project]

openapi_python_client/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def generate(
120120
meta: MetaType = _meta_option,
121121
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
122122
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
123+
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
123124
fail_on_warning: bool = False,
124125
) -> None:
125126
"""Generate a new OpenAPI Client library"""
@@ -146,6 +147,7 @@ def generate(
146147
custom_template_path=custom_template_path,
147148
file_encoding=file_encoding,
148149
config=config,
150+
output_path=output_path,
149151
)
150152
handle_errors(errors, fail_on_warning)
151153

@@ -159,6 +161,7 @@ def update(
159161
meta: MetaType = _meta_option,
160162
file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"),
161163
config_path: Optional[pathlib.Path] = CONFIG_OPTION,
164+
output_path: Optional[pathlib.Path] = typer.Option(None, help="Set a path to store the api client"),
162165
fail_on_warning: bool = False,
163166
) -> None:
164167
"""Update an existing OpenAPI Client library
@@ -189,5 +192,6 @@ def update(
189192
custom_template_path=custom_template_path,
190193
file_encoding=file_encoding,
191194
config=config,
195+
output_path=output_path,
192196
)
193197
handle_errors(errors, fail_on_warning)

0 commit comments

Comments
 (0)