openapi-spec-tools 0.18.0__tar.gz → 0.20.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.18.0 → openapi_spec_tools-0.20.0}/.gitignore +4 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/PKG-INFO +15 -6
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/README.md +9 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/__init__.py +3 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/api_gen/__init__.py +5 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/api_gen/_environment.py +35 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/api_gen/api_generator.py +58 -36
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/api_gen/flat_generator.py +4 -4
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/api_gen/opaque_generator.py +4 -4
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/api_gen/property_generator.py +5 -5
- openapi_spec_tools-0.20.0/openapi_spec_tools/base_gen/__init__.py +17 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/base_gen/_requests.py +6 -5
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/base_gen/base_generator.py +168 -62
- openapi_spec_tools-0.20.0/openapi_spec_tools/base_gen/config.py +63 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/base_gen/constants.py +60 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/base_gen/files.py +7 -23
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/base_gen/utils.py +4 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/__init__.py +1 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/analyze.py +16 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/api_gen.py +28 -33
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/arguments.py +23 -6
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/cli_gen.py +43 -54
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/content.py +44 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/history.py +4 -4
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/layout.py +20 -18
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/models.py +186 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/oas.py +212 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/operations.py +277 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/paths.py +119 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli/tags.py +89 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli/utils.py +98 -7
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli_gen/__init__.py +7 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli_gen/_arguments.py +1 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli_gen/_tree.py +1 -6
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli_gen/cli_generator.py +131 -35
- openapi_spec_tools-0.20.0/openapi_spec_tools/cli_gen/files.py +82 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/constants.py +5 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/expand.py +104 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/flatten.py +303 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/layout/__init__.py +25 -0
- openapi_spec_tools-0.20.0/openapi_spec_tools/layout/config.py +40 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/layout/layout_generator.py +60 -28
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/layout/utils.py +7 -2
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/types.py +10 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/utils.py +30 -7
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/pyproject.toml +18 -10
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_cli_generator.py +89 -33
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_files.py +11 -66
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_main.py +1 -1
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_tree.py +1 -1
- openapi_spec_tools-0.18.0/openapi_spec_tools/api_gen/_environment.py +0 -19
- openapi_spec_tools-0.18.0/openapi_spec_tools/api_gen/files.py +0 -54
- openapi_spec_tools-0.18.0/openapi_spec_tools/base_gen/constants.py +0 -9
- openapi_spec_tools-0.18.0/openapi_spec_tools/cli/oas.py +0 -712
- openapi_spec_tools-0.18.0/openapi_spec_tools/cli_gen/constants.py +0 -2
- openapi_spec_tools-0.18.0/openapi_spec_tools/cli_gen/files.py +0 -181
- openapi_spec_tools-0.18.0/tests/cli_gen/helpers.py +0 -11
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/LICENSE +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/base_gen/_logging.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli_gen/_display.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/cli_gen/_exceptions.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/layout/merge.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/openapi_spec_tools/layout/types.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/__init__.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_display.py +0 -0
- {openapi_spec_tools-0.18.0 → openapi_spec_tools-0.20.0}/tests/cli_gen/test_exceptions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: openapi-spec-tools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.20.0
|
|
4
4
|
Summary: OpenAPI specification tools for analyzing, updating, and generating a CLI.
|
|
5
5
|
Project-URL: Homepage, https://github.com/rickwporter/openapi-spec-tools
|
|
6
6
|
Project-URL: Repository, https://github.com/rickwporter/openapi-spec-tools
|
|
@@ -25,12 +25,12 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
25
25
|
Classifier: Topic :: Utilities
|
|
26
26
|
Classifier: Typing :: Typed
|
|
27
27
|
Requires-Python: <4,>=3.10
|
|
28
|
-
Requires-Dist: gitpython
|
|
28
|
+
Requires-Dist: gitpython>=3.2.0
|
|
29
29
|
Requires-Dist: pydantic<3,>=2.13.3
|
|
30
|
-
Requires-Dist: pyyaml
|
|
31
|
-
Requires-Dist: requests
|
|
32
|
-
Requires-Dist: rich-objects>=0.3.
|
|
33
|
-
Requires-Dist: rich
|
|
30
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
31
|
+
Requires-Dist: requests>=2.34.2
|
|
32
|
+
Requires-Dist: rich-objects>=0.3.1
|
|
33
|
+
Requires-Dist: rich>=15.0.0
|
|
34
34
|
Requires-Dist: typer>=0.27.2
|
|
35
35
|
Description-Content-Type: text/markdown
|
|
36
36
|
|
|
@@ -75,6 +75,10 @@ Found Pet is used by 3 operations:
|
|
|
75
75
|
(.env) %
|
|
76
76
|
```
|
|
77
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
|
+
|
|
78
82
|
## CLI Generation
|
|
79
83
|
|
|
80
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.
|
|
@@ -114,10 +118,15 @@ Into code that produces a CLI that has commands like:
|
|
|
114
118
|
|
|
115
119
|
See the examples in `examples/` for some more complete works.
|
|
116
120
|
|
|
121
|
+
The CLI generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
122
|
+
|
|
123
|
+
|
|
117
124
|
## API Generation
|
|
118
125
|
|
|
119
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.
|
|
120
127
|
|
|
128
|
+
The API generator can be configured using a YAML file. For more details, see [GEN_CONFIG.md](GEN_CONFIG.md).
|
|
129
|
+
|
|
121
130
|
## Contributing
|
|
122
131
|
|
|
123
132
|
The [DEVELOPMENT.md](DEVELOPMENT.md) has more information about getting setup as a developer.
|
|
@@ -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.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"""Implementation for several utilities for analyzing and modifying OpenAPI specifications."""
|
|
2
|
+
from openapi_spec_tools.expand import expand_schema
|
|
3
|
+
from openapi_spec_tools.expand import merge_schema
|
|
4
|
+
from openapi_spec_tools.flatten import flatten_schema
|
|
2
5
|
from openapi_spec_tools.utils import count_values
|
|
3
6
|
from openapi_spec_tools.utils import find_diffs
|
|
4
7
|
from openapi_spec_tools.utils import find_paths
|
|
@@ -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.18.0 → openapi_spec_tools-0.20.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."""
|
|
@@ -96,20 +101,20 @@ from datetime import datetime # noqa: F401
|
|
|
96
101
|
from enum import Enum # noqa: F401
|
|
97
102
|
from typing import Any
|
|
98
103
|
|
|
99
|
-
from {self.package_name} import _environment as _e
|
|
100
|
-
from {self.package_name} import _logging as _l
|
|
101
|
-
from {self.package_name} import _requests as _r
|
|
104
|
+
from {self.package_name} import _environment as _e
|
|
105
|
+
from {self.package_name} import _logging as _l
|
|
106
|
+
from {self.package_name} import _requests as _r
|
|
102
107
|
"""
|
|
103
108
|
|
|
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}',
|
|
@@ -156,7 +161,7 @@ from {self.package_name} import _requests as _r # noqa: F401
|
|
|
156
161
|
if allow_required and required and schema_default is None:
|
|
157
162
|
arg_default = ""
|
|
158
163
|
else:
|
|
159
|
-
if not required:
|
|
164
|
+
if not required or schema_default is None:
|
|
160
165
|
py_type = f"{py_type} | None"
|
|
161
166
|
if schema_default is None:
|
|
162
167
|
arg_default = " = None"
|
|
@@ -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.18.0 → openapi_spec_tools-0.20.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.18.0 → openapi_spec_tools-0.20.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)
|
|
@@ -191,7 +192,7 @@ def request(
|
|
|
191
192
|
try:
|
|
192
193
|
content = response.content.decode(encoding=encoding, errors="ignore")
|
|
193
194
|
return yaml.safe_load(content)
|
|
194
|
-
except Exception as ex:
|
|
195
|
+
except Exception as ex: # noqa: BLE001
|
|
195
196
|
logger.error(f"Failed to decode {method} {pretty_url} response: {ex}")
|
|
196
197
|
return None
|
|
197
198
|
|
|
@@ -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
|
|