openapi-python-generator 1.0.1.dev1732809362__tar.gz → 1.0.1.dev1732810010__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/PKG-INFO +1 -1
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/pyproject.toml +1 -1
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/setup.py +1 -1
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/__main__.py +1 -1
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/generate_data.py +41 -9
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/LICENSE +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/README.md +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/__init__.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/common.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/__init__.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/__init__.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/api_config_generator.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/common.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/generator.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/jinja_config.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/model_generator.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/service_generator.py +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/aiohttp.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/apiconfig.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/apiconfig_pydantic_2.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/enum.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/httpx.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/models.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/models_pydantic_2.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/requests.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/language_converters/python/templates/service.jinja2 +0 -0
- {openapi_python_generator-1.0.1.dev1732809362 → openapi_python_generator-1.0.1.dev1732810010}/src/openapi_python_generator/models.py +0 -0
|
@@ -29,7 +29,7 @@ entry_points = \
|
|
|
29
29
|
|
|
30
30
|
setup_kwargs = {
|
|
31
31
|
'name': 'openapi-python-generator',
|
|
32
|
-
'version': '1.0.1.
|
|
32
|
+
'version': '1.0.1.dev1732810010',
|
|
33
33
|
'description': 'Openapi Python Generator',
|
|
34
34
|
'long_description': "# Openapi Python Generator\n\n[][pypi_]\n[][status]\n[][python version]\n[][license]\n\n[][documentation]\n[][tests]\n[][codecov]\n\n[][pre-commit]\n[][black]\n\n[pypi_]: https://pypi.org/project/openapi-python-generator/\n[status]: https://pypi.org/project/openapi-python-generator/\n[python version]: https://pypi.org/project/openapi-python-generator\n[documentation]: https://marcomuellner.github.io/openapi-python-generator/\n[tests]: https://github.com/MarcoMuellner/openapi-python-generator/actions?workflow=Tests\n[codecov]: https://app.codecov.io/gh/MarcoMuellner/openapi-python-generator\n[pre-commit]: https://github.com/pre-commit/pre-commit\n[black]: https://github.com/psf/black\n\n\n\n---\n__Documentation:__ [here][documentation]\n\n---\n\n## Features\n\n- __Ease of use__. Provide input, output and the library, and the generator will do the rest.\n- __Type safety and type hinting.__ __OpenAPI python generator__ makes heavy use of pydantic models to provide type-safe data structures.\n- __Support for multiple rest frameworks.__ __OpenAPI python generator__ currently supports the following:\n - [httpx](https://pypi.org/project/httpx/)\n - [requests](https://pypi.org/project/requests/)\n - [aiohttp](https://pypi.org/project/aiohttp/)\n- __Async and sync code generation support__, depending on the framework. It will automatically create both for frameworks that support both.\n- __Easily extendable using Jinja2 templates__. The code is designed to be easily extendable and should support even more languages and frameworks in the future.\n- __Fully tested__. Every generated code is automatically tested against the OpenAPI spec and we have 100% coverage.\n- __Usage as CLI or as library__.\n\n## Requirements\n\n- Python 3.7+\n\n## Installation\n\nYou can install _Openapi Python Generator_ via [pip] from [PyPI]:\n\n```console\n$ pip install openapi-python-generator\n```\n\n## Usage\n\nPlease see the [Quick start page] for details.\n\n## Roadmap\n\n- Support for all commonly used http libraries in the python ecosystem (~~requests~~, urllib, ...)\n- Support for multiple languages\n- Support for multiple authentication schemes\n- Support custom themes\n\n## Contributing\n\nContributions are very welcome.\nTo learn more, see the [Contributor Guide].\n\n## License\n\nDistributed under the terms of the [MIT license][license],\n_Openapi Python Generator_ is free and open source software.\n\n## Issues\n\nIf you encounter any problems,\nplease [file an issue] along with a detailed description.\n\n## Credits\n\nSpecial thanks to the peeps from [openapi-schema-pydantic](https://github.com/kuimono/openapi-schema-pydantic),\nwhich already did a lot of the legwork by providing a pydantic schema for the OpenAPI 3.0.0+ specification.\n\nThis project was generated from [@cjolowicz]'s [Hypermodern Python Cookiecutter] template.\n\n[@cjolowicz]: https://github.com/cjolowicz\n[pypi]: https://pypi.org/\n[hypermodern python cookiecutter]: https://github.com/cjolowicz/cookiecutter-hypermodern-python\n[file an issue]: https://github.com/MarcoMuellner/openapi-python-generator/issues\n[pip]: https://pip.pypa.io/\n\n<!-- github-only -->\n\n[license]: https://github.com/MarcoMuellner/openapi-python-generator/blob/main/LICENSE\n[contributor guide]: https://github.com/MarcoMuellner/openapi-python-generator/blob/main/CONTRIBUTING.md\n[Quick start page]: https://marcomuellner.github.io/openapi-python-generator/quick_start/\n",
|
|
35
35
|
'author': 'Marco Müllner',
|
|
@@ -19,7 +19,7 @@ from openapi_python_generator.generate_data import generate_data
|
|
|
19
19
|
)
|
|
20
20
|
@click.option(
|
|
21
21
|
"--env-token-name",
|
|
22
|
-
default=
|
|
22
|
+
default="access_token",
|
|
23
23
|
show_default=True,
|
|
24
24
|
help="Name of the environment variable that contains the token. If you set this, the code expects this environment "
|
|
25
25
|
"variable to be set and will raise an error if it is not.",
|
|
@@ -7,6 +7,7 @@ import click
|
|
|
7
7
|
import httpx
|
|
8
8
|
import isort
|
|
9
9
|
import orjson
|
|
10
|
+
import yaml
|
|
10
11
|
from black import NothingChanged
|
|
11
12
|
from httpx import ConnectError
|
|
12
13
|
from httpx import ConnectTimeout
|
|
@@ -45,30 +46,61 @@ def write_code(path: Path, content) -> None:
|
|
|
45
46
|
|
|
46
47
|
def get_open_api(source: Union[str, Path]) -> OpenAPI:
|
|
47
48
|
"""
|
|
48
|
-
Tries to fetch the openapi
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
Tries to fetch the openapi specification file from the web or load from a local file.
|
|
50
|
+
Supports both JSON and YAML formats. Returns the according OpenAPI object.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
source: URL or file path to the OpenAPI specification
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
OpenAPI: Parsed OpenAPI specification object
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
FileNotFoundError: If the specified file cannot be found
|
|
60
|
+
ConnectError: If the URL cannot be accessed
|
|
61
|
+
ValidationError: If the specification is invalid
|
|
62
|
+
JSONDecodeError/YAMLError: If the file cannot be parsed
|
|
51
63
|
"""
|
|
52
64
|
try:
|
|
65
|
+
# Handle remote files
|
|
53
66
|
if not isinstance(source, Path) and (
|
|
54
|
-
|
|
67
|
+
source.startswith("http://") or source.startswith("https://")
|
|
55
68
|
):
|
|
56
|
-
|
|
69
|
+
content = httpx.get(source).text
|
|
70
|
+
# Try JSON first, then YAML for remote files
|
|
71
|
+
try:
|
|
72
|
+
return OpenAPI(**orjson.loads(content))
|
|
73
|
+
except orjson.JSONDecodeError:
|
|
74
|
+
return OpenAPI(**yaml.safe_load(content))
|
|
57
75
|
|
|
76
|
+
# Handle local files
|
|
58
77
|
with open(source, "r") as f:
|
|
59
78
|
file_content = f.read()
|
|
60
|
-
|
|
79
|
+
|
|
80
|
+
# Try JSON first
|
|
81
|
+
try:
|
|
82
|
+
return OpenAPI(**orjson.loads(file_content))
|
|
83
|
+
except orjson.JSONDecodeError:
|
|
84
|
+
# If JSON fails, try YAML
|
|
85
|
+
try:
|
|
86
|
+
return OpenAPI(**yaml.safe_load(file_content))
|
|
87
|
+
except yaml.YAMLError as e:
|
|
88
|
+
click.echo(
|
|
89
|
+
f"File {source} is neither a valid JSON nor YAML file: {str(e)}"
|
|
90
|
+
)
|
|
91
|
+
raise
|
|
92
|
+
|
|
61
93
|
except FileNotFoundError:
|
|
62
94
|
click.echo(
|
|
63
|
-
f"File {source} not found. Please make sure to pass the path to the OpenAPI
|
|
95
|
+
f"File {source} not found. Please make sure to pass the path to the OpenAPI specification."
|
|
64
96
|
)
|
|
65
97
|
raise
|
|
66
98
|
except (ConnectError, ConnectTimeout):
|
|
67
99
|
click.echo(f"Could not connect to {source}.")
|
|
68
100
|
raise ConnectError(f"Could not connect to {source}.") from None
|
|
69
|
-
except
|
|
101
|
+
except ValidationError:
|
|
70
102
|
click.echo(
|
|
71
|
-
f"File {source} is not a valid OpenAPI 3.0 specification
|
|
103
|
+
f"File {source} is not a valid OpenAPI 3.0 specification."
|
|
72
104
|
)
|
|
73
105
|
raise
|
|
74
106
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|