pydantic-openapi-generator 2.2.8__py3-none-any.whl
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.
- pydantic_openapi_generator/__init__.py +17 -0
- pydantic_openapi_generator/__main__.py +85 -0
- pydantic_openapi_generator/common.py +58 -0
- pydantic_openapi_generator/generate_data.py +235 -0
- pydantic_openapi_generator/language_converters/__init__.py +0 -0
- pydantic_openapi_generator/language_converters/python/__init__.py +0 -0
- pydantic_openapi_generator/language_converters/python/client_generator.py +495 -0
- pydantic_openapi_generator/language_converters/python/common.py +58 -0
- pydantic_openapi_generator/language_converters/python/exception_generator.py +23 -0
- pydantic_openapi_generator/language_converters/python/generator.py +61 -0
- pydantic_openapi_generator/language_converters/python/jinja_config.py +38 -0
- pydantic_openapi_generator/language_converters/python/model_generator.py +1024 -0
- pydantic_openapi_generator/language_converters/python/templates/alias_union.jinja2 +17 -0
- pydantic_openapi_generator/language_converters/python/templates/async_client_httpx_pydantic_2.jinja2 +151 -0
- pydantic_openapi_generator/language_converters/python/templates/discriminator_enum.jinja2 +7 -0
- pydantic_openapi_generator/language_converters/python/templates/enum.jinja2 +11 -0
- pydantic_openapi_generator/language_converters/python/templates/http_exception.jinja2 +8 -0
- pydantic_openapi_generator/language_converters/python/templates/models.jinja2 +24 -0
- pydantic_openapi_generator/language_converters/python/templates/models_pydantic_2.jinja2 +28 -0
- pydantic_openapi_generator/language_converters/python/templates/sync_client_httpx_pydantic_2.jinja2 +150 -0
- pydantic_openapi_generator/models.py +86 -0
- pydantic_openapi_generator/parsers/__init__.py +13 -0
- pydantic_openapi_generator/parsers/openapi_30.py +65 -0
- pydantic_openapi_generator/parsers/openapi_31.py +65 -0
- pydantic_openapi_generator/py.typed +0 -0
- pydantic_openapi_generator/version_detector.py +67 -0
- pydantic_openapi_generator-2.2.8.dist-info/METADATA +141 -0
- pydantic_openapi_generator-2.2.8.dist-info/RECORD +31 -0
- pydantic_openapi_generator-2.2.8.dist-info/WHEEL +4 -0
- pydantic_openapi_generator-2.2.8.dist-info/entry_points.txt +2 -0
- pydantic_openapi_generator-2.2.8.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
OpenAPI version detection utilities.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, Literal
|
|
6
|
+
|
|
7
|
+
OpenAPIVersion = Literal["3.0", "3.1"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def detect_openapi_version(spec_data: Dict[str, Any]) -> OpenAPIVersion:
|
|
11
|
+
"""
|
|
12
|
+
Detect the OpenAPI version from specification data.
|
|
13
|
+
|
|
14
|
+
Performs basic validation to ensure the specification is well-formed enough
|
|
15
|
+
to route to the appropriate parser. The actual parser will handle detailed
|
|
16
|
+
validation of the specification content.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
spec_data: Dictionary containing OpenAPI specification
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
OpenAPIVersion: Either "3.0" or "3.1"
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
ValueError: If the specification is malformed or has unsupported version
|
|
26
|
+
"""
|
|
27
|
+
# Basic validation: must be a dictionary
|
|
28
|
+
if not isinstance(spec_data, dict):
|
|
29
|
+
raise ValueError("OpenAPI specification must be a dictionary/object")
|
|
30
|
+
|
|
31
|
+
# Basic validation: must have openapi field
|
|
32
|
+
if "openapi" not in spec_data:
|
|
33
|
+
raise ValueError("Missing required 'openapi' field in specification")
|
|
34
|
+
|
|
35
|
+
openapi_version = spec_data.get("openapi")
|
|
36
|
+
|
|
37
|
+
# Basic validation: openapi field must be a string
|
|
38
|
+
if not isinstance(openapi_version, str):
|
|
39
|
+
raise ValueError("'openapi' field must be a string")
|
|
40
|
+
|
|
41
|
+
# Basic validation: must not be empty
|
|
42
|
+
if not openapi_version.strip():
|
|
43
|
+
raise ValueError("'openapi' field cannot be empty")
|
|
44
|
+
|
|
45
|
+
# Version detection
|
|
46
|
+
if openapi_version.startswith("3.0"):
|
|
47
|
+
return "3.0"
|
|
48
|
+
elif openapi_version.startswith("3.1"):
|
|
49
|
+
return "3.1"
|
|
50
|
+
else:
|
|
51
|
+
raise ValueError(f"Unsupported OpenAPI version: {openapi_version}. Only OpenAPI 3.0.x and 3.1.x are supported.")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def is_openapi_30(spec_data: Dict[str, Any]) -> bool:
|
|
55
|
+
"""Check if the specification is OpenAPI 3.0.x"""
|
|
56
|
+
try:
|
|
57
|
+
return detect_openapi_version(spec_data) == "3.0"
|
|
58
|
+
except ValueError:
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def is_openapi_31(spec_data: Dict[str, Any]) -> bool:
|
|
63
|
+
"""Check if the specification is OpenAPI 3.1.x"""
|
|
64
|
+
try:
|
|
65
|
+
return detect_openapi_version(spec_data) == "3.1"
|
|
66
|
+
except ValueError:
|
|
67
|
+
return False
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pydantic-openapi-generator
|
|
3
|
+
Version: 2.2.8
|
|
4
|
+
Summary: Openapi Python Generator
|
|
5
|
+
Project-URL: Homepage, https://github.com/mattcoulter7/pydantic-openapi-generator
|
|
6
|
+
Project-URL: Repository, https://github.com/mattcoulter7/pydantic-openapi-generator
|
|
7
|
+
Project-URL: Documentation, https://github.com/mattcoulter7/pydantic-openapi-generator
|
|
8
|
+
Project-URL: Changelog, https://github.com/mattcoulter7/pydantic-openapi-generator/releases
|
|
9
|
+
Author-email: Marco Müllner <muellnermarco@gmail.com>, Matt Coulter <mattcoul7@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: Generator,OpenAPI,Python,async
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Requires-Python: <4,>=3.12
|
|
15
|
+
Requires-Dist: black>=21.10b0
|
|
16
|
+
Requires-Dist: click<9,>=8.1.3
|
|
17
|
+
Requires-Dist: httpx[all]<0.29,>=0.28.0
|
|
18
|
+
Requires-Dist: importlib-metadata<9,>=8.7.0
|
|
19
|
+
Requires-Dist: isort>=5.10.1
|
|
20
|
+
Requires-Dist: jinja2<4,>=3.1.2
|
|
21
|
+
Requires-Dist: openapi-pydantic<0.6,>=0.5.1
|
|
22
|
+
Requires-Dist: orjson<4,>=3.9.15
|
|
23
|
+
Requires-Dist: pydantic<3,>=2.10.2
|
|
24
|
+
Requires-Dist: pyyaml<7,>=6.0.2
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# Pydantic OpenAPI Generator
|
|
28
|
+
|
|
29
|
+
[][pypi_]
|
|
30
|
+
[][status]
|
|
31
|
+
[][python version]
|
|
32
|
+
[][license]
|
|
33
|
+
|
|
34
|
+
[][documentation]
|
|
35
|
+
[][tests]
|
|
36
|
+
[][codecov]
|
|
37
|
+
|
|
38
|
+
[][pre-commit]
|
|
39
|
+
[][black]
|
|
40
|
+
|
|
41
|
+
[pypi_]: https://pypi.org/project/pydantic-openapi-generator/
|
|
42
|
+
[status]: https://pypi.org/project/pydantic-openapi-generator/
|
|
43
|
+
[python version]: https://pypi.org/project/pydantic-openapi-generator
|
|
44
|
+
[documentation]: https://github.com/mattcoulter7/pydantic-openapi-generator
|
|
45
|
+
[tests]: https://github.com/mattcoulter7/pydantic-openapi-generator/actions/workflows/ci.yaml
|
|
46
|
+
[codecov]: https://app.codecov.io/gh/mattcoulter7/pydantic-openapi-generator
|
|
47
|
+
[pre-commit]: https://github.com/pre-commit/pre-commit
|
|
48
|
+
[black]: https://github.com/psf/black
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
__Documentation:__ [here][documentation]
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Migration from auth-broker
|
|
58
|
+
|
|
59
|
+
As of `pydantic-openapi-generator` version `2.2.8`, this package has moved out
|
|
60
|
+
of the `auth-broker` organisation, been renamed, and had its import namespace
|
|
61
|
+
updated.
|
|
62
|
+
|
|
63
|
+
| Item | Previous | Current |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| GitHub repository | [`auth-broker/openapi-python-generator`](https://github.com/auth-broker/openapi-python-generator) | [`mattcoulter7/pydantic-openapi-generator`](https://github.com/mattcoulter7/pydantic-openapi-generator) |
|
|
66
|
+
| PyPI package | [`ab-openapi-python-generator`](https://pypi.org/project/ab-openapi-python-generator/) | [`pydantic-openapi-generator`](https://pypi.org/project/pydantic-openapi-generator/) |
|
|
67
|
+
| CLI command | `ab-openapi-python-generator` | `pydantic-openapi-generator` |
|
|
68
|
+
| Import namespace | `ab_openapi_python_generator` | `pydantic_openapi_generator` |
|
|
69
|
+
|
|
70
|
+
The old PyPI package is retained as an archived historical package. New work
|
|
71
|
+
should use `pydantic-openapi-generator` and `pydantic_openapi_generator`.
|
|
72
|
+
|
|
73
|
+
## Features
|
|
74
|
+
|
|
75
|
+
- __Ease of use__. Provide input, output and the library, and the generator will do the rest.
|
|
76
|
+
- __Type safety and type hinting.__ __Pydantic OpenAPI Generator__ makes heavy use of pydantic models to provide type-safe data structures.
|
|
77
|
+
- __Support for multiple rest frameworks.__ __Pydantic OpenAPI Generator__ currently supports the following:
|
|
78
|
+
- [httpx](https://pypi.org/project/httpx/)
|
|
79
|
+
- [requests](https://pypi.org/project/requests/)
|
|
80
|
+
- [aiohttp](https://pypi.org/project/aiohttp/)
|
|
81
|
+
- __Async and sync code generation support__, depending on the framework. It will automatically create both for frameworks that support both.
|
|
82
|
+
- __Easily extendable using Jinja2 templates__. The code is designed to be easily extendable and should support even more languages and frameworks in the future.
|
|
83
|
+
- __Fully tested__. Every generated code is automatically tested against the OpenAPI spec and we have 100% coverage.
|
|
84
|
+
- __Usage as CLI or as library__.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Python 3.12+
|
|
89
|
+
|
|
90
|
+
## Installation
|
|
91
|
+
|
|
92
|
+
You can install _Pydantic OpenAPI Generator_ via [pip] from [PyPI]:
|
|
93
|
+
|
|
94
|
+
```console
|
|
95
|
+
$ pip install pydantic-openapi-generator
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
Please see the [Quick start page] for details.
|
|
101
|
+
|
|
102
|
+
## Roadmap
|
|
103
|
+
|
|
104
|
+
- Support for all commonly used http libraries in the python ecosystem (~~requests~~, urllib, ...)
|
|
105
|
+
- Support for multiple languages
|
|
106
|
+
- Support for multiple authentication schemes
|
|
107
|
+
- Support custom themes
|
|
108
|
+
|
|
109
|
+
## Contributing
|
|
110
|
+
|
|
111
|
+
Contributions are very welcome.
|
|
112
|
+
To learn more, see the [Contributor Guide].
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
Distributed under the terms of the [MIT license][license],
|
|
117
|
+
_Openapi Python Generator_ is free and open source software.
|
|
118
|
+
|
|
119
|
+
## Issues
|
|
120
|
+
|
|
121
|
+
If you encounter any problems,
|
|
122
|
+
please [file an issue] along with a detailed description.
|
|
123
|
+
|
|
124
|
+
## Credits
|
|
125
|
+
|
|
126
|
+
Special thanks to the peeps from [openapi-schema-pydantic](https://github.com/kuimono/openapi-schema-pydantic),
|
|
127
|
+
which already did a lot of the legwork by providing a pydantic schema for the OpenAPI 3.0.0+ specification.
|
|
128
|
+
|
|
129
|
+
This project was generated from [@cjolowicz]'s [Hypermodern Python Cookiecutter] template.
|
|
130
|
+
|
|
131
|
+
[@cjolowicz]: https://github.com/cjolowicz
|
|
132
|
+
[pypi]: https://pypi.org/
|
|
133
|
+
[hypermodern python cookiecutter]: https://github.com/cjolowicz/cookiecutter-hypermodern-python
|
|
134
|
+
[file an issue]: https://github.com/mattcoulter7/pydantic-openapi-generator/issues
|
|
135
|
+
[pip]: https://pip.pypa.io/
|
|
136
|
+
|
|
137
|
+
<!-- github-only -->
|
|
138
|
+
|
|
139
|
+
[license]: https://github.com/mattcoulter7/pydantic-openapi-generator/blob/main/LICENSE
|
|
140
|
+
[contributor guide]: https://github.com/mattcoulter7/pydantic-openapi-generator/blob/main/CONTRIBUTING.md
|
|
141
|
+
[Quick start page]: https://github.com/mattcoulter7/pydantic-openapi-generator#usage
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
pydantic_openapi_generator/__init__.py,sha256=ph2EznAu4nkHFruaG542m4TQ_xAvDlf36uKxtAkVP1s,460
|
|
2
|
+
pydantic_openapi_generator/__main__.py,sha256=IH3k_bpPr0zDIx3aB_q--5jMqBuvcuVT6scrj-72eP8,2497
|
|
3
|
+
pydantic_openapi_generator/common.py,sha256=ii8KAkTvuUGiWILGUNtLx_S_Ut21Rq6riNvbwDNwIew,1220
|
|
4
|
+
pydantic_openapi_generator/generate_data.py,sha256=s71eWNKqEv5_v0Tfb2jnIME-JOag_Jz9gKxMGT5Veq8,7944
|
|
5
|
+
pydantic_openapi_generator/models.py,sha256=pkuEbp4FrLhgoTzEZKnCVYBBvefX1oMJdbKAoMDTHfA,2031
|
|
6
|
+
pydantic_openapi_generator/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
pydantic_openapi_generator/version_detector.py,sha256=PUDTpgDMHljUzxhLhMrCzHMdS3mgYQibWDiI4-vLRB4,2104
|
|
8
|
+
pydantic_openapi_generator/language_converters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
pydantic_openapi_generator/language_converters/python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
pydantic_openapi_generator/language_converters/python/client_generator.py,sha256=mMqKRZZVrjbYC2quCKWfyJxoLXu1HfWesg8S2vSF3Ns,19397
|
|
11
|
+
pydantic_openapi_generator/language_converters/python/common.py,sha256=gZHNhVC4OwGBlmr3h9Ffz3iILO1ykva9CrqhBfeYQXU,1616
|
|
12
|
+
pydantic_openapi_generator/language_converters/python/exception_generator.py,sha256=VWpoDhc8kZfFsdJC7hwyPG-zdszYsn75yslu2gKovm4,651
|
|
13
|
+
pydantic_openapi_generator/language_converters/python/generator.py,sha256=uwwh6qLpoQCR__1J5ccA1Z7G7ewu5Ab2D--bgZsWOKE,2103
|
|
14
|
+
pydantic_openapi_generator/language_converters/python/jinja_config.py,sha256=B-qSmxfrplroItvHLS7fp-FC_PkroJLT9fsB5-9J0oI,1267
|
|
15
|
+
pydantic_openapi_generator/language_converters/python/model_generator.py,sha256=iU4JObTxTO1xMUZfenoXBGNOAhLSxlS80f7pNxxGqa8,42546
|
|
16
|
+
pydantic_openapi_generator/language_converters/python/templates/alias_union.jinja2,sha256=tndnrDky4srNRyB_HnUMZFW7HtoJvEfwIFteYIu0ELc,468
|
|
17
|
+
pydantic_openapi_generator/language_converters/python/templates/async_client_httpx_pydantic_2.jinja2,sha256=GOJWwbALdHwTnj3UUB6O5kPBqCHJNiG_WzukJtXpcsI,5017
|
|
18
|
+
pydantic_openapi_generator/language_converters/python/templates/discriminator_enum.jinja2,sha256=GJZ_ih1eURnJRPZq5P_3aKhYB5iJHymj2fpuNSdM90Y,163
|
|
19
|
+
pydantic_openapi_generator/language_converters/python/templates/enum.jinja2,sha256=7dewyMLifUTe9xjCTE62deuncPiNkp7eGkIaY-IWsLo,263
|
|
20
|
+
pydantic_openapi_generator/language_converters/python/templates/http_exception.jinja2,sha256=BHy48PD74aU74NGWC98iciacmGotHuWw9CaOqnCL8Kc,294
|
|
21
|
+
pydantic_openapi_generator/language_converters/python/templates/models.jinja2,sha256=s5PllbxiEENsZ5_fKSh1gKMJWhcLfBdH5744nKnAZsQ,797
|
|
22
|
+
pydantic_openapi_generator/language_converters/python/templates/models_pydantic_2.jinja2,sha256=o6-OlV5upoZOAVx6aQbsaigPMTCi4Uuec-oP1FNDJ60,904
|
|
23
|
+
pydantic_openapi_generator/language_converters/python/templates/sync_client_httpx_pydantic_2.jinja2,sha256=MaFsVuKq5K0rEldlc_HZEU98MdFCXSEKFznxJHKMl3U,4862
|
|
24
|
+
pydantic_openapi_generator/parsers/__init__.py,sha256=UITDIV7rp3HAA1M8kQc_9cNG6e1tS2vDa4mTKua6aMY,300
|
|
25
|
+
pydantic_openapi_generator/parsers/openapi_30.py,sha256=1fQw_kWPJa91MycncQ-3Nk4yRiB2xZjTWutZGnBvVQE,1920
|
|
26
|
+
pydantic_openapi_generator/parsers/openapi_31.py,sha256=rTK-qaYjsF8SMjglcz9lPULwc4AuQykzgytDhORIqhA,1920
|
|
27
|
+
pydantic_openapi_generator-2.2.8.dist-info/METADATA,sha256=2IOAso4QDjYWH3szD4S02eF46oQ1EZ4ZyZJBlTZz4tQ,6223
|
|
28
|
+
pydantic_openapi_generator-2.2.8.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
29
|
+
pydantic_openapi_generator-2.2.8.dist-info/entry_points.txt,sha256=2LNJMXRbxmRkcRNdH7FOaGD0Te_xFojGNGsjQoOdPoQ,88
|
|
30
|
+
pydantic_openapi_generator-2.2.8.dist-info/licenses/LICENSE,sha256=0myanGwJ2vUOZN12aN95o0My6XEysnnVlbKikYw3pHg,1070
|
|
31
|
+
pydantic_openapi_generator-2.2.8.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2022 Marco Müllner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|