-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy path__main__.py
More file actions
86 lines (80 loc) · 2.65 KB
/
__main__.py
File metadata and controls
86 lines (80 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from typing import Optional
import click
from openapi_python_generator import __version__
from openapi_python_generator.common import Formatter, HTTPLibrary, PydanticVersion
from openapi_python_generator.generate_data import generate_data
@click.command()
@click.argument("source")
@click.argument("output")
@click.option(
"--library",
default=HTTPLibrary.httpx,
type=HTTPLibrary,
show_default=True,
help="HTTP library to use in the generation of the client.",
)
@click.option(
"--env-token-name",
default=None,
show_default=True,
help="Name of the environment variable that contains the token. If you set this, the code expects this environment "
"variable to be set and will raise an error if it is not.",
)
@click.option(
"--use-orjson",
is_flag=True,
show_default=True,
default=False,
help="Use the orjson library to serialize the data. This is faster than the default json library and provides "
"serialization of datetimes and other types that are not supported by the default json library.",
)
@click.option(
"--use-awaredatetime",
is_flag=True,
show_default=True,
default=False,
help="Use timezone-aware datetime objects instead of naive datetime objects. This ensures proper handling of "
"timezone information in the generated models.",
)
@click.option(
"--custom-template-path",
type=str,
default=None,
help="Custom template path to use. Allows overriding of the built in templates",
)
@click.option(
"--pydantic-version",
type=click.Choice(["v1", "v2"]),
default="v2",
show_default=True,
help="Pydantic version to use for generated models.",
)
@click.option(
"--formatter",
type=click.Choice(["black", "none"]),
default="black",
show_default=True,
help="Option to choose which auto formatter is applied.",
)
@click.version_option(version=__version__)
def main(
source: str,
output: str,
library: Optional[HTTPLibrary] = HTTPLibrary.httpx,
env_token_name: Optional[str] = None,
use_orjson: bool = False,
use_awaredatetime: bool = False,
custom_template_path: Optional[str] = None,
pydantic_version: PydanticVersion = PydanticVersion.V2,
formatter: Formatter = Formatter.BLACK,
) -> None:
"""
Generate Python code from an OpenAPI 3.0 specification.
Provide a SOURCE (file or URL) containing the OpenAPI 3 specification and
an OUTPUT path, where the resulting client is created.
"""
generate_data(
source, output, library, env_token_name, use_orjson, use_awaredatetime, custom_template_path, pydantic_version, formatter
)
if __name__ == "__main__": # pragma: no cover
main()