openapi-spec-tools 0.17.2__tar.gz → 0.19.0__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_spec_tools-0.19.0/.gitignore +171 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/PKG-INFO +24 -17
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/README.md +10 -1
- openapi_spec_tools-0.19.0/openapi_spec_tools/api_gen/__init__.py +5 -0
- openapi_spec_tools-0.19.0/openapi_spec_tools/api_gen/_environment.py +35 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/api_generator.py +54 -32
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/flat_generator.py +4 -4
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/opaque_generator.py +4 -4
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/property_generator.py +5 -5
- openapi_spec_tools-0.19.0/openapi_spec_tools/base_gen/__init__.py +17 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/_requests.py +5 -4
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/base_generator.py +160 -51
- openapi_spec_tools-0.19.0/openapi_spec_tools/base_gen/config.py +63 -0
- openapi_spec_tools-0.19.0/openapi_spec_tools/base_gen/constants.py +60 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/files.py +7 -23
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/utils.py +4 -0
- openapi_spec_tools-0.19.0/openapi_spec_tools/cli/__init__.py +1 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/api_gen.py +28 -33
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/arguments.py +7 -9
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/cli_gen.py +43 -54
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/history.py +3 -3
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/layout.py +64 -16
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/utils.py +43 -4
- openapi_spec_tools-0.19.0/openapi_spec_tools/cli_gen/__init__.py +7 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli_gen/_arguments.py +1 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli_gen/_tree.py +1 -4
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli_gen/cli_generator.py +108 -23
- openapi_spec_tools-0.19.0/openapi_spec_tools/cli_gen/files.py +82 -0
- openapi_spec_tools-0.19.0/openapi_spec_tools/layout/__init__.py +25 -0
- openapi_spec_tools-0.19.0/openapi_spec_tools/layout/config.py +40 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/layout/layout_generator.py +54 -18
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/layout/merge.py +24 -1
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/layout/types.py +28 -4
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/layout/utils.py +109 -68
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/utils.py +14 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/pyproject.toml +39 -29
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_cli_generator.py +74 -27
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_files.py +7 -64
- openapi_spec_tools-0.17.2/openapi_spec_tools/api_gen/_environment.py +0 -19
- openapi_spec_tools-0.17.2/openapi_spec_tools/api_gen/files.py +0 -54
- openapi_spec_tools-0.17.2/openapi_spec_tools/base_gen/constants.py +0 -9
- openapi_spec_tools-0.17.2/openapi_spec_tools/cli_gen/constants.py +0 -2
- openapi_spec_tools-0.17.2/openapi_spec_tools/cli_gen/files.py +0 -181
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/LICENSE +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/__init__.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/_logging.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli/oas.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli_gen/_display.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/cli_gen/_exceptions.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/types.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/__init__.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/helpers.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_display.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_exceptions.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_main.py +0 -0
- {openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/tests/cli_gen/test_tree.py +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
#.idea/
|
|
169
|
+
|
|
170
|
+
# PyPI configuration file
|
|
171
|
+
.pypirc
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: openapi-spec-tools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.19.0
|
|
4
4
|
Summary: OpenAPI specification tools for analyzing, updating, and generating a CLI.
|
|
5
|
+
Project-URL: Homepage, https://github.com/rickwporter/openapi-spec-tools
|
|
6
|
+
Project-URL: Repository, https://github.com/rickwporter/openapi-spec-tools
|
|
7
|
+
Author-email: Rick Porter <rickwporter@gmail.com>
|
|
5
8
|
License-File: LICENSE
|
|
6
|
-
Author: Rick Porter
|
|
7
|
-
Author-email: rickwporter@gmail.com
|
|
8
|
-
Requires-Python: >=3.10,<4.0
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
10
10
|
Classifier: Environment :: Console
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
13
|
Classifier: Programming Language :: Python
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
16
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
17
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
18
|
Classifier: Programming Language :: Python :: 3.12
|
|
18
19
|
Classifier: Programming Language :: Python :: 3.13
|
|
19
20
|
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
21
|
Classifier: Topic :: Software Development
|
|
22
22
|
Classifier: Topic :: Software Development :: Code Generators
|
|
23
23
|
Classifier: Topic :: Software Development :: Libraries
|
|
24
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
25
|
Classifier: Topic :: Utilities
|
|
26
26
|
Classifier: Typing :: Typed
|
|
27
|
-
Requires-
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist:
|
|
32
|
-
Requires-Dist: rich-objects
|
|
33
|
-
Requires-Dist:
|
|
34
|
-
|
|
35
|
-
Project-URL: Repository, https://github.com/rickwporter/openapi-spec-tools
|
|
27
|
+
Requires-Python: <4,>=3.10
|
|
28
|
+
Requires-Dist: gitpython>=3.2.0
|
|
29
|
+
Requires-Dist: pydantic<3,>=2.13.3
|
|
30
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
31
|
+
Requires-Dist: requests>=2.34.2
|
|
32
|
+
Requires-Dist: rich-objects>=0.3.0
|
|
33
|
+
Requires-Dist: rich>=15.0.0
|
|
34
|
+
Requires-Dist: typer>=0.27.2
|
|
36
35
|
Description-Content-Type: text/markdown
|
|
37
36
|
|
|
38
37
|
# openapi-spec-tools
|
|
@@ -44,7 +43,7 @@ This is a collection of tools for using OpenAPI specifications. The OpenAPI comm
|
|
|
44
43
|
The project has been published to PyPi, so you should be able to install it with something like one of the following (depending on how you do Python package management):
|
|
45
44
|
```terminal
|
|
46
45
|
% pip install openapi-spec-tools
|
|
47
|
-
%
|
|
46
|
+
% uv add openapi-spec-tools
|
|
48
47
|
```
|
|
49
48
|
|
|
50
49
|
Generally, there are two intended ways to utilize this package:
|
|
@@ -76,6 +75,10 @@ Found Pet is used by 3 operations:
|
|
|
76
75
|
(.env) %
|
|
77
76
|
```
|
|
78
77
|
|
|
78
|
+
## Layout
|
|
79
|
+
|
|
80
|
+
The CLI and API generation allow users to specify a layout file to reduce assumptions. More information about the layout generation, format and schema are covered in [LAYOUT.md](LAYOUT.md).
|
|
81
|
+
|
|
79
82
|
## CLI Generation
|
|
80
83
|
|
|
81
84
|
The `cli-gen` tool allows users to create a user-friendly CLI using the OpenAPI spec and a layout file. The layout file provides the CLI structure and refers to the OpenAPI spec for details of operations. [LAYOUT.md](LAYOUT.md) has more details about the layout file, and the [CLI_GEN.md](CLI_GEN.md) has more info about CLI generation.
|
|
@@ -115,13 +118,17 @@ Into code that produces a CLI that has commands like:
|
|
|
115
118
|
|
|
116
119
|
See the examples in `examples/` for some more complete works.
|
|
117
120
|
|
|
121
|
+
The CLI generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
122
|
+
|
|
123
|
+
|
|
118
124
|
## API Generation
|
|
119
125
|
|
|
120
126
|
The `api-gen` tool allows users to generate API code using the OpenAPI spec. The generated Python code provides type hints and helpful comments, but does no real checking of the arguments and/or return values. The return values are typically dictionaries instead of a data class, such as the models provided in the standard OpenAPI generator.
|
|
121
127
|
|
|
128
|
+
The API generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
129
|
+
|
|
122
130
|
## Contributing
|
|
123
131
|
|
|
124
132
|
The [DEVELOPMENT.md](DEVELOPMENT.md) has more information about getting setup as a developer.
|
|
125
133
|
|
|
126
134
|
The [TODO.md](TODO.md) has some ideas where this project can be improved and expanded -- please add your ideas here, or email Rick directly (rickwporter@gmail.com).
|
|
127
|
-
|
|
@@ -7,7 +7,7 @@ This is a collection of tools for using OpenAPI specifications. The OpenAPI comm
|
|
|
7
7
|
The project has been published to PyPi, so you should be able to install it with something like one of the following (depending on how you do Python package management):
|
|
8
8
|
```terminal
|
|
9
9
|
% pip install openapi-spec-tools
|
|
10
|
-
%
|
|
10
|
+
% uv add openapi-spec-tools
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Generally, there are two intended ways to utilize this package:
|
|
@@ -39,6 +39,10 @@ Found Pet is used by 3 operations:
|
|
|
39
39
|
(.env) %
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
## Layout
|
|
43
|
+
|
|
44
|
+
The CLI and API generation allow users to specify a layout file to reduce assumptions. More information about the layout generation, format and schema are covered in [LAYOUT.md](LAYOUT.md).
|
|
45
|
+
|
|
42
46
|
## CLI Generation
|
|
43
47
|
|
|
44
48
|
The `cli-gen` tool allows users to create a user-friendly CLI using the OpenAPI spec and a layout file. The layout file provides the CLI structure and refers to the OpenAPI spec for details of operations. [LAYOUT.md](LAYOUT.md) has more details about the layout file, and the [CLI_GEN.md](CLI_GEN.md) has more info about CLI generation.
|
|
@@ -78,10 +82,15 @@ Into code that produces a CLI that has commands like:
|
|
|
78
82
|
|
|
79
83
|
See the examples in `examples/` for some more complete works.
|
|
80
84
|
|
|
85
|
+
The CLI generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
86
|
+
|
|
87
|
+
|
|
81
88
|
## API Generation
|
|
82
89
|
|
|
83
90
|
The `api-gen` tool allows users to generate API code using the OpenAPI spec. The generated Python code provides type hints and helpful comments, but does no real checking of the arguments and/or return values. The return values are typically dictionaries instead of a data class, such as the models provided in the standard OpenAPI generator.
|
|
84
91
|
|
|
92
|
+
The API generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
93
|
+
|
|
85
94
|
## Contributing
|
|
86
95
|
|
|
87
96
|
The [DEVELOPMENT.md](DEVELOPMENT.md) has more information about getting setup as a developer.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def env_string(varnames: str | list[str], default: str | None = None, except_missing: bool = False) -> str | None:
|
|
5
|
+
"""Get string value from environment.
|
|
6
|
+
|
|
7
|
+
When no value is found, return the default or throw a ValueError (if except_missing is True).
|
|
8
|
+
"""
|
|
9
|
+
varnames = [varnames] if isinstance(varnames, str) else varnames
|
|
10
|
+
|
|
11
|
+
for varname in varnames:
|
|
12
|
+
value = os.environ.get(varname)
|
|
13
|
+
if value is not None:
|
|
14
|
+
return value
|
|
15
|
+
|
|
16
|
+
if except_missing:
|
|
17
|
+
raise ValueError(f"Missing {', '.join(varnames)} value(s)")
|
|
18
|
+
return default
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def env_int(varnames: str | list[str], default: int | None = None, except_missing: bool = False) -> int | None:
|
|
22
|
+
"""Get integer value from environment.
|
|
23
|
+
|
|
24
|
+
When no value is found, return the default or throw a ValueError (if except_missing is True).
|
|
25
|
+
"""
|
|
26
|
+
varnames = [varnames] if isinstance(varnames, str) else varnames
|
|
27
|
+
|
|
28
|
+
for varname in varnames:
|
|
29
|
+
value = os.environ.get(varname)
|
|
30
|
+
if value is not None:
|
|
31
|
+
return int(value)
|
|
32
|
+
|
|
33
|
+
if except_missing:
|
|
34
|
+
raise ValueError(f"Missing {', '.join(varnames)} value(s)")
|
|
35
|
+
return default
|
{openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/api_generator.py
RENAMED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
"""Declares the abstract ApiGenerator base class that is the basis for API generation.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Shared API generation behavior lives here. Subclasses implement function_definition(), which
|
|
4
|
+
generate_files() uses when writing modules.
|
|
5
5
|
"""
|
|
6
|
+
import os
|
|
6
7
|
from abc import ABC
|
|
7
8
|
from abc import abstractmethod
|
|
9
|
+
from pathlib import Path
|
|
8
10
|
from typing import Any
|
|
9
11
|
|
|
10
|
-
from openapi_spec_tools.base_gen
|
|
11
|
-
from openapi_spec_tools.base_gen
|
|
12
|
-
from openapi_spec_tools.base_gen
|
|
13
|
-
from openapi_spec_tools.base_gen
|
|
14
|
-
from openapi_spec_tools.base_gen
|
|
15
|
-
from openapi_spec_tools.base_gen
|
|
16
|
-
from openapi_spec_tools.
|
|
12
|
+
from openapi_spec_tools.base_gen import COLLECTIONS
|
|
13
|
+
from openapi_spec_tools.base_gen import SEP1
|
|
14
|
+
from openapi_spec_tools.base_gen import BaseGenerator
|
|
15
|
+
from openapi_spec_tools.base_gen import maybe_quoted
|
|
16
|
+
from openapi_spec_tools.base_gen import quoted
|
|
17
|
+
from openapi_spec_tools.base_gen import simple_escape
|
|
18
|
+
from openapi_spec_tools.base_gen import to_snake_case
|
|
19
|
+
from openapi_spec_tools.layout import LayoutNode
|
|
17
20
|
from openapi_spec_tools.types import OasField
|
|
18
21
|
|
|
19
|
-
DEFAULT_VAR_HOST = "API_HOST"
|
|
20
|
-
DEFAULT_VAR_KEY = "API_KEY"
|
|
21
|
-
DEFAULT_VAR_TIMEOUT = "API_TIMEOUT"
|
|
22
22
|
DEFAULT_VAR_LOG_LEVEL = "API_LOG_LEVEL"
|
|
23
23
|
DEFAULT_VALUE_LOG_LEVEL = "info"
|
|
24
|
-
DEFAULT_VALUE_TIMEOUT = 5
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
class ApiGenerator(BaseGenerator, ABC):
|
|
@@ -34,25 +33,31 @@ class ApiGenerator(BaseGenerator, ABC):
|
|
|
34
33
|
|
|
35
34
|
def __init__(
|
|
36
35
|
self,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
env_host: str = DEFAULT_VAR_HOST,
|
|
40
|
-
env_key: str = DEFAULT_VAR_KEY,
|
|
41
|
-
env_timeout: str = DEFAULT_VAR_TIMEOUT,
|
|
42
|
-
env_log_level: str = DEFAULT_VAR_LOG_LEVEL,
|
|
36
|
+
*args,
|
|
37
|
+
env_log_level: str | list[str] = DEFAULT_VAR_LOG_LEVEL,
|
|
43
38
|
default_log_level: str = DEFAULT_VALUE_LOG_LEVEL,
|
|
44
|
-
default_timeout: int = DEFAULT_VALUE_TIMEOUT,
|
|
45
39
|
**kwargs,
|
|
46
40
|
):
|
|
47
41
|
"""Initialize with the OpenAPI spec and other data for generating multiple modules."""
|
|
48
|
-
super().__init__(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
super().__init__(*args, env_log_level=env_log_level, default_log_level=default_log_level, **kwargs)
|
|
43
|
+
|
|
44
|
+
def default_infra_files(self) -> dict[Path, str]:
|
|
45
|
+
"""Default files to copy from source."""
|
|
46
|
+
api_gen = Path(__file__).parent
|
|
47
|
+
base_gen = Path(__file__).parent.parent / "base_gen"
|
|
48
|
+
return {
|
|
49
|
+
base_gen / "_logging.py": "_logging.py",
|
|
50
|
+
base_gen / "_requests.py": "_requests.py",
|
|
51
|
+
api_gen / "_environment.py": "_environment.py",
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
def default_infra_replacements(self) -> dict[str, str]:
|
|
55
|
+
"""Default infrastructure line replacements."""
|
|
56
|
+
return {
|
|
57
|
+
"openapi_spec_tools.api_gen": self.package_name,
|
|
58
|
+
"openapi_spec_tools.base_gen": self.package_name,
|
|
59
|
+
__package__: self.package_name,
|
|
60
|
+
}
|
|
56
61
|
|
|
57
62
|
def property_help(self, prop: dict[str, Any]) -> str:
|
|
58
63
|
"""Get the short help string for the specified property."""
|
|
@@ -104,12 +109,12 @@ from {self.package_name} import _requests as _r # noqa: F401
|
|
|
104
109
|
def init_infra_args(self, operation: dict[str, Any]) -> str:
|
|
105
110
|
"""Provide initialization of standard arguments inside body."""
|
|
106
111
|
host_default = (
|
|
107
|
-
f'_e.env_string({
|
|
112
|
+
f'_e.env_string({maybe_quoted(self.env_host)}, '
|
|
108
113
|
f'default={quoted(self.default_host)}, except_missing=True)'
|
|
109
114
|
)
|
|
110
|
-
key_default = f'_e.env_string({
|
|
111
|
-
timeout_default = f'_e.env_int({
|
|
112
|
-
log_default = f'_e.env_string({
|
|
115
|
+
key_default = f'_e.env_string({maybe_quoted(self.env_key)}, except_missing=True)'
|
|
116
|
+
timeout_default = f'_e.env_int({maybe_quoted(self.env_timeout)}, default={self.default_timeout})'
|
|
117
|
+
log_default = f'_e.env_string({maybe_quoted(self.env_log_level)}, default={quoted(self.default_log)})'
|
|
113
118
|
lines = [
|
|
114
119
|
f'_api_host = _api_host or {host_default}',
|
|
115
120
|
f'_api_key = _api_key or {key_default}',
|
|
@@ -191,3 +196,20 @@ from {self.package_name} import _requests as _r # noqa: F401
|
|
|
191
196
|
def function_definition(self, command: LayoutNode) -> str:
|
|
192
197
|
"""Provide function definition for specified command."""
|
|
193
198
|
pass # pragma: no cover
|
|
199
|
+
|
|
200
|
+
def generate_files(self, node: LayoutNode, directory: str) -> None:
|
|
201
|
+
"""Create a module for the current node, and recursively generate sub-commands."""
|
|
202
|
+
if node.operations():
|
|
203
|
+
module_name = to_snake_case(node.identifier)
|
|
204
|
+
self.logger.info(f"Generating {module_name} module")
|
|
205
|
+
text = self.copyright
|
|
206
|
+
text += self.standard_imports()
|
|
207
|
+
for command in node.operations():
|
|
208
|
+
text += self.function_definition(command)
|
|
209
|
+
|
|
210
|
+
filename = os.path.join(directory, module_name + ".py")
|
|
211
|
+
with open(filename, "w", encoding="utf-8", newline="\n") as fp:
|
|
212
|
+
fp.write(text)
|
|
213
|
+
|
|
214
|
+
for command in node.subcommands():
|
|
215
|
+
self.generate_files(command, directory)
|
{openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/api_gen/flat_generator.py
RENAMED
|
@@ -4,10 +4,10 @@ The bodies are "unrolled" to individual parameters (as best as possible), and pa
|
|
|
4
4
|
parameters into the functions.
|
|
5
5
|
"""
|
|
6
6
|
from openapi_spec_tools.api_gen.api_generator import ApiGenerator
|
|
7
|
-
from openapi_spec_tools.base_gen
|
|
8
|
-
from openapi_spec_tools.base_gen
|
|
9
|
-
from openapi_spec_tools.base_gen
|
|
10
|
-
from openapi_spec_tools.layout
|
|
7
|
+
from openapi_spec_tools.base_gen import NL
|
|
8
|
+
from openapi_spec_tools.base_gen import SEP1
|
|
9
|
+
from openapi_spec_tools.base_gen import quoted
|
|
10
|
+
from openapi_spec_tools.layout import LayoutNode
|
|
11
11
|
from openapi_spec_tools.types import OasField
|
|
12
12
|
|
|
13
13
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
from typing import Any
|
|
3
3
|
|
|
4
4
|
from openapi_spec_tools.api_gen.api_generator import ApiGenerator
|
|
5
|
-
from openapi_spec_tools.base_gen
|
|
6
|
-
from openapi_spec_tools.base_gen
|
|
7
|
-
from openapi_spec_tools.base_gen
|
|
8
|
-
from openapi_spec_tools.layout
|
|
5
|
+
from openapi_spec_tools.base_gen import NL
|
|
6
|
+
from openapi_spec_tools.base_gen import SEP1
|
|
7
|
+
from openapi_spec_tools.base_gen import quoted
|
|
8
|
+
from openapi_spec_tools.layout import LayoutNode
|
|
9
9
|
from openapi_spec_tools.types import OasField
|
|
10
10
|
|
|
11
11
|
|
|
@@ -3,11 +3,11 @@ from copy import deepcopy
|
|
|
3
3
|
from typing import Any
|
|
4
4
|
|
|
5
5
|
from openapi_spec_tools.api_gen.api_generator import ApiGenerator
|
|
6
|
-
from openapi_spec_tools.base_gen
|
|
7
|
-
from openapi_spec_tools.base_gen
|
|
8
|
-
from openapi_spec_tools.base_gen
|
|
9
|
-
from openapi_spec_tools.base_gen
|
|
10
|
-
from openapi_spec_tools.layout
|
|
6
|
+
from openapi_spec_tools.base_gen import NL
|
|
7
|
+
from openapi_spec_tools.base_gen import SEP1
|
|
8
|
+
from openapi_spec_tools.base_gen import quoted
|
|
9
|
+
from openapi_spec_tools.base_gen import shallow
|
|
10
|
+
from openapi_spec_tools.layout import LayoutNode
|
|
11
11
|
from openapi_spec_tools.types import OasField
|
|
12
12
|
|
|
13
13
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Base generator which is the base class for API and CLI generoators."""
|
|
2
|
+
from .base_generator import BaseGenerator
|
|
3
|
+
from .config import GeneratorConfig
|
|
4
|
+
from .constants import COLLECTIONS
|
|
5
|
+
from .constants import NL
|
|
6
|
+
from .constants import SEP1
|
|
7
|
+
from .constants import SEP2
|
|
8
|
+
from .utils import is_case_sensitive
|
|
9
|
+
from .utils import maybe_quoted
|
|
10
|
+
from .utils import prepend
|
|
11
|
+
from .utils import quoted
|
|
12
|
+
from .utils import replace_special
|
|
13
|
+
from .utils import set_missing
|
|
14
|
+
from .utils import shallow
|
|
15
|
+
from .utils import simple_escape
|
|
16
|
+
from .utils import to_camel_case
|
|
17
|
+
from .utils import to_snake_case
|
{openapi_spec_tools-0.17.2 → openapi_spec_tools-0.19.0}/openapi_spec_tools/base_gen/_requests.py
RENAMED
|
@@ -8,6 +8,7 @@ import json
|
|
|
8
8
|
from copy import deepcopy
|
|
9
9
|
from datetime import datetime
|
|
10
10
|
from datetime import timedelta
|
|
11
|
+
from datetime import timezone
|
|
11
12
|
from typing import Any
|
|
12
13
|
|
|
13
14
|
import requests
|
|
@@ -168,9 +169,9 @@ def request(
|
|
|
168
169
|
params = params or {}
|
|
169
170
|
pretty_url = url + _pretty_params(params)
|
|
170
171
|
logger.debug(f"Requesting {method} {pretty_url}")
|
|
171
|
-
start = datetime.now()
|
|
172
|
+
start = datetime.now(tz=timezone.utc)
|
|
172
173
|
response = requests.request(method, url, params=params, headers=headers, json=body, timeout=timeout, **kwargs)
|
|
173
|
-
delta = datetime.now() - start
|
|
174
|
+
delta = datetime.now(tz=timezone.utc) - start
|
|
174
175
|
logger.info(f"Got {response.status_code} response from {method} {pretty_url} in {delta.total_seconds()}")
|
|
175
176
|
|
|
176
177
|
raise_for_error(response)
|
|
@@ -256,9 +257,9 @@ def depaginate(
|
|
|
256
257
|
pretty_url = _url + _pretty_params(_params)
|
|
257
258
|
|
|
258
259
|
logger.debug(f"Requesting {GET} {pretty_url} count={page_count + 1}")
|
|
259
|
-
start = datetime.now()
|
|
260
|
+
start = datetime.now(tz=timezone.utc)
|
|
260
261
|
response = requests.get(_url, params=deepcopy(_params), headers=_headers, timeout=timeout)
|
|
261
|
-
delta = datetime.now() - start
|
|
262
|
+
delta = datetime.now(tz=timezone.utc) - start
|
|
262
263
|
|
|
263
264
|
raise_for_error(response)
|
|
264
265
|
|