openapi-spec-tools 0.21.0__tar.gz → 0.22.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.21.0 → openapi_spec_tools-0.22.0}/PKG-INFO +7 -5
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/README.md +2 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/api_generator.py +5 -2
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/flat_generator.py +4 -1
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/opaque_generator.py +4 -1
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/property_generator.py +4 -1
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/_logging.py +6 -4
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/base_generator.py +10 -13
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/constants.py +33 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/api_gen.py +4 -5
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/cli_gen.py +22 -23
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/content.py +2 -3
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/layout.py +13 -14
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/models.py +13 -13
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/oas.py +9 -10
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/operations.py +12 -13
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/paths.py +8 -8
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/tags.py +10 -9
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/utils.py +10 -6
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/cli_generator.py +7 -4
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/expand.py +2 -3
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/flatten.py +2 -3
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/layout_generator.py +9 -5
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/utils.py +29 -3
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/pyproject.toml +5 -5
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_cli_generator.py +1 -1
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_files.py +1 -1
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/.gitignore +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/LICENSE +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/_environment.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/_requests.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/config.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/files.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/utils.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/analyze.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/arguments.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/constants.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli/history.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/_arguments.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/_display.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/_exceptions.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/_tree.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/cli_gen/files.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/constants.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/config.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/merge.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/types.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/layout/utils.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/types.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/__init__.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_display.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_exceptions.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_main.py +0 -0
- {openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/tests/cli_gen/test_tree.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.22.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,15 +25,17 @@ 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>=3.2.
|
|
29
|
-
Requires-Dist: pydantic<3,>=2.
|
|
28
|
+
Requires-Dist: gitpython>=3.2.1
|
|
29
|
+
Requires-Dist: pydantic<3,>=2.14.3
|
|
30
30
|
Requires-Dist: pyyaml>=6.0.3
|
|
31
31
|
Requires-Dist: requests>=2.34.2
|
|
32
|
-
Requires-Dist: rich-objects>=0.
|
|
32
|
+
Requires-Dist: rich-objects>=0.4.0
|
|
33
33
|
Requires-Dist: rich>=15.0.0
|
|
34
|
-
Requires-Dist: typer>=0.
|
|
34
|
+
Requires-Dist: typer>=0.29.1
|
|
35
35
|
Description-Content-Type: text/markdown
|
|
36
36
|
|
|
37
|
+
[](https://codecov.io/gh/rickwporter/openapi-spec-tools)
|
|
38
|
+
|
|
37
39
|
# openapi-spec-tools
|
|
38
40
|
|
|
39
41
|
This is a collection of tools for using OpenAPI specifications. The OpenAPI community has a plethora of tools, and this is intended to supplement those. The tools here provide functionality that has not been readily available elsewhere.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://codecov.io/gh/rickwporter/openapi-spec-tools)
|
|
2
|
+
|
|
1
3
|
# openapi-spec-tools
|
|
2
4
|
|
|
3
5
|
This is a collection of tools for using OpenAPI specifications. The OpenAPI community has a plethora of tools, and this is intended to supplement those. The tools here provide functionality that has not been readily available elsewhere.
|
{openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/api_generator.py
RENAMED
|
@@ -18,10 +18,13 @@ from openapi_spec_tools.base_gen import simple_escape
|
|
|
18
18
|
from openapi_spec_tools.base_gen import to_snake_case
|
|
19
19
|
from openapi_spec_tools.layout import LayoutNode
|
|
20
20
|
from openapi_spec_tools.types import OasField
|
|
21
|
+
from openapi_spec_tools.utils import get_logger
|
|
21
22
|
|
|
22
23
|
DEFAULT_VAR_LOG_LEVEL = "API_LOG_LEVEL"
|
|
23
24
|
DEFAULT_VALUE_LOG_LEVEL = "info"
|
|
24
25
|
|
|
26
|
+
logger = get_logger(__name__)
|
|
27
|
+
|
|
25
28
|
|
|
26
29
|
class ApiGenerator(BaseGenerator, ABC):
|
|
27
30
|
"""Provides the majority of the CLI generation functions.
|
|
@@ -153,7 +156,7 @@ from {self.package_name} import _requests as _r
|
|
|
153
156
|
py_type = self.get_parameter_pytype(prop)
|
|
154
157
|
if not py_type:
|
|
155
158
|
# log an error and use 'Any'
|
|
156
|
-
|
|
159
|
+
logger.error(f"Unable to determine Python type for {prop}")
|
|
157
160
|
py_type = 'Any'
|
|
158
161
|
|
|
159
162
|
if collection:
|
|
@@ -201,7 +204,7 @@ from {self.package_name} import _requests as _r
|
|
|
201
204
|
"""Create a module for the current node, and recursively generate sub-commands."""
|
|
202
205
|
if node.operations():
|
|
203
206
|
module_name = to_snake_case(node.identifier)
|
|
204
|
-
|
|
207
|
+
logger.info(f"Generating {module_name} module")
|
|
205
208
|
text = self.copyright
|
|
206
209
|
text += self.standard_imports()
|
|
207
210
|
for command in node.operations():
|
{openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/api_gen/flat_generator.py
RENAMED
|
@@ -9,6 +9,9 @@ from openapi_spec_tools.base_gen import SEP1
|
|
|
9
9
|
from openapi_spec_tools.base_gen import quoted
|
|
10
10
|
from openapi_spec_tools.layout import LayoutNode
|
|
11
11
|
from openapi_spec_tools.types import OasField
|
|
12
|
+
from openapi_spec_tools.utils import get_logger
|
|
13
|
+
|
|
14
|
+
logger = get_logger(__name__)
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
class FlatApiGenerator(ApiGenerator):
|
|
@@ -59,7 +62,7 @@ class FlatApiGenerator(ApiGenerator):
|
|
|
59
62
|
func_args.extend(self.command_infra_arguments(node))
|
|
60
63
|
args_str = SEP1 + SEP1.join(func_args) + NL
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
logger.debug(f"{func_name}({len(path_params)} path, {len(query_params)} query, {len(body_params)} body)")
|
|
63
66
|
|
|
64
67
|
user_header_init = ""
|
|
65
68
|
user_header_arg = ""
|
|
@@ -7,6 +7,9 @@ from openapi_spec_tools.base_gen import SEP1
|
|
|
7
7
|
from openapi_spec_tools.base_gen import quoted
|
|
8
8
|
from openapi_spec_tools.layout import LayoutNode
|
|
9
9
|
from openapi_spec_tools.types import OasField
|
|
10
|
+
from openapi_spec_tools.utils import get_logger
|
|
11
|
+
|
|
12
|
+
logger = get_logger(__name__)
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
class OpaqueApiGenerator(ApiGenerator):
|
|
@@ -77,7 +80,7 @@ class OpaqueApiGenerator(ApiGenerator):
|
|
|
77
80
|
func_args.extend(self.command_infra_arguments(node))
|
|
78
81
|
args_str = SEP1 + SEP1.join(func_args) + NL
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
logger.debug(f"{func_name}({len(path_params)} path, {len(query_params)} query")
|
|
81
84
|
|
|
82
85
|
user_header_init = ""
|
|
83
86
|
user_header_arg = ""
|
|
@@ -11,6 +11,9 @@ from openapi_spec_tools.flatten import apply_one_of
|
|
|
11
11
|
from openapi_spec_tools.flatten import flatten_collection
|
|
12
12
|
from openapi_spec_tools.layout import LayoutNode
|
|
13
13
|
from openapi_spec_tools.types import OasField
|
|
14
|
+
from openapi_spec_tools.utils import get_logger
|
|
15
|
+
|
|
16
|
+
logger = get_logger(__name__)
|
|
14
17
|
|
|
15
18
|
|
|
16
19
|
class PropertyApiGenerator(ApiGenerator):
|
|
@@ -113,7 +116,7 @@ class PropertyApiGenerator(ApiGenerator):
|
|
|
113
116
|
func_args.extend(self.command_infra_arguments(node))
|
|
114
117
|
args_str = SEP1 + SEP1.join(func_args) + NL
|
|
115
118
|
|
|
116
|
-
|
|
119
|
+
logger.debug(f"{func_name}({len(path_params)} path, {len(query_params)} query")
|
|
117
120
|
|
|
118
121
|
user_header_init = ""
|
|
119
122
|
user_header_arg = ""
|
{openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/_logging.py
RENAMED
|
@@ -14,12 +14,14 @@ class LogLevel(str, Enum):
|
|
|
14
14
|
DEBUG = "debug"
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def get_logger(
|
|
18
|
-
|
|
17
|
+
def get_logger() -> logging.Logger:
|
|
18
|
+
"""Get the logger for LOG_CLASS."""
|
|
19
|
+
return logging.getLogger(name=LOG_CLASS)
|
|
19
20
|
|
|
20
21
|
|
|
21
|
-
def init_logging(level: LogLevel
|
|
22
|
+
def init_logging(level: LogLevel) -> logging.Logger:
|
|
23
|
+
"""Initialize the LOG_CLASS logger and sets the level."""
|
|
22
24
|
logging.basicConfig(format=LOG_FORMAT, datefmt=LOG_DATE_FMT)
|
|
23
|
-
logger = get_logger(
|
|
25
|
+
logger = get_logger()
|
|
24
26
|
logger.setLevel(level.upper())
|
|
25
27
|
return logger
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"""Declares the Generator class that is used for most of the CLi generation capability."""
|
|
2
|
-
import logging
|
|
3
2
|
import textwrap
|
|
4
3
|
from copy import deepcopy
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
from typing import Any
|
|
7
6
|
|
|
8
|
-
from openapi_spec_tools.base_gen._logging import init_logging
|
|
9
7
|
from openapi_spec_tools.base_gen.config import GeneratorConfig
|
|
10
8
|
from openapi_spec_tools.base_gen.constants import COLLECTIONS
|
|
11
9
|
from openapi_spec_tools.base_gen.constants import DEFAULT_CONFLICT_SUFFIX
|
|
@@ -36,10 +34,11 @@ from openapi_spec_tools.flatten import is_simple_type
|
|
|
36
34
|
from openapi_spec_tools.types import ContentType
|
|
37
35
|
from openapi_spec_tools.types import OasField
|
|
38
36
|
from openapi_spec_tools.utils import _or
|
|
37
|
+
from openapi_spec_tools.utils import get_logger
|
|
39
38
|
from openapi_spec_tools.utils import map_operations
|
|
40
39
|
from openapi_spec_tools.utils import reference_classname
|
|
41
40
|
|
|
42
|
-
|
|
41
|
+
logger = get_logger(__name__)
|
|
43
42
|
|
|
44
43
|
|
|
45
44
|
class BaseGenerator:
|
|
@@ -53,7 +52,6 @@ class BaseGenerator:
|
|
|
53
52
|
def __init__(
|
|
54
53
|
self,
|
|
55
54
|
oas: dict[str, Any],
|
|
56
|
-
logger: logging.Logger | None = None,
|
|
57
55
|
config: GeneratorConfig | None = None,
|
|
58
56
|
package_name: str | None = None,
|
|
59
57
|
supported_content: list[ContentType] | None = None,
|
|
@@ -101,7 +99,6 @@ class BaseGenerator:
|
|
|
101
99
|
config = config or GeneratorConfig() # reduce logic by creating a default (if no config provided)
|
|
102
100
|
self.operations = map_operations(oas.get(OasField.PATHS, {}))
|
|
103
101
|
self.components = oas.get(OasField.COMPONENTS, {})
|
|
104
|
-
self.logger = logger or init_logging("INFO", LOG_CLASS)
|
|
105
102
|
|
|
106
103
|
self.package_name = _or(package_name, config.package_name, ValueError("Missing package_name"))
|
|
107
104
|
self.default_host = _or(default_host, config.default_host, "")
|
|
@@ -223,7 +220,8 @@ class BaseGenerator:
|
|
|
223
220
|
if not line:
|
|
224
221
|
result += NL
|
|
225
222
|
else:
|
|
226
|
-
|
|
223
|
+
_line = line.replace("'''", "\\'''") # avoid breaking docstring
|
|
224
|
+
inner = textwrap.wrap(_line, width=self.max_help_length, replace_whitespace=False)
|
|
227
225
|
result += SEP1 + SEP1.join(inner)
|
|
228
226
|
result += f"{SEP1}'''{SEP1}"
|
|
229
227
|
return result
|
|
@@ -368,10 +366,10 @@ class BaseGenerator:
|
|
|
368
366
|
# find first item from schema this is a non-null type
|
|
369
367
|
item = next((item for item in schema if item in reduced), None)
|
|
370
368
|
if item is not None:
|
|
371
|
-
|
|
369
|
+
logger.debug(f"Choosing {item} type from {', '.join(schema)}")
|
|
372
370
|
return item
|
|
373
371
|
|
|
374
|
-
|
|
372
|
+
logger.warning(f"Unable to simplify type for {schema}")
|
|
375
373
|
return None
|
|
376
374
|
|
|
377
375
|
|
|
@@ -613,11 +611,9 @@ class BaseGenerator:
|
|
|
613
611
|
"""Check to see if value can be directly used as a variable name."""
|
|
614
612
|
if not isinstance(value, str):
|
|
615
613
|
return False
|
|
616
|
-
|
|
617
|
-
|
|
614
|
+
# Names cannot start with a digit, including values like "1", "1.0", "1st" or "1.2.3".
|
|
615
|
+
if value[:1].isdigit():
|
|
618
616
|
return False
|
|
619
|
-
except ValueError:
|
|
620
|
-
pass
|
|
621
617
|
|
|
622
618
|
return True
|
|
623
619
|
|
|
@@ -689,7 +685,8 @@ class BaseGenerator:
|
|
|
689
685
|
dup_counts = dict.fromkeys(duplicates, 0)
|
|
690
686
|
declarations = []
|
|
691
687
|
for v in values:
|
|
692
|
-
|
|
688
|
+
var_name = self.variable_name(str(v)) or "empty"
|
|
689
|
+
base_name = var_name.upper()
|
|
693
690
|
suffix = ""
|
|
694
691
|
if base_name in dup_counts:
|
|
695
692
|
suffix = dup_counts[base_name]
|
{openapi_spec_tools-0.21.0 → openapi_spec_tools-0.22.0}/openapi_spec_tools/base_gen/constants.py
RENAMED
|
@@ -33,28 +33,61 @@ DEFAULT_VALUE_TIMEOUT = 5
|
|
|
33
33
|
# This is an incomplete list of Python builtins and imports that should avoided in variable names
|
|
34
34
|
DEFAULT_RESERVED = {
|
|
35
35
|
"all",
|
|
36
|
+
"Annotated",
|
|
37
|
+
"and",
|
|
36
38
|
"any",
|
|
39
|
+
"as",
|
|
40
|
+
"assert",
|
|
41
|
+
"async",
|
|
42
|
+
"await",
|
|
37
43
|
"bool",
|
|
44
|
+
"break",
|
|
38
45
|
"breakpoint",
|
|
46
|
+
"case",
|
|
39
47
|
"class",
|
|
40
48
|
"continue",
|
|
41
49
|
"date",
|
|
42
50
|
"datetime",
|
|
51
|
+
"def",
|
|
43
52
|
"dict",
|
|
53
|
+
"del",
|
|
54
|
+
"else",
|
|
55
|
+
"elif",
|
|
44
56
|
"except",
|
|
57
|
+
"False",
|
|
58
|
+
"finally",
|
|
45
59
|
"float",
|
|
46
60
|
"for",
|
|
47
61
|
"format",
|
|
62
|
+
"from",
|
|
63
|
+
"global",
|
|
64
|
+
"if",
|
|
65
|
+
"import",
|
|
48
66
|
"in",
|
|
49
67
|
"input",
|
|
50
68
|
"int",
|
|
69
|
+
"is",
|
|
70
|
+
"lambda",
|
|
51
71
|
"list",
|
|
72
|
+
"match",
|
|
52
73
|
"max",
|
|
53
74
|
"min",
|
|
75
|
+
"None",
|
|
76
|
+
"none",
|
|
77
|
+
"nonlocal",
|
|
78
|
+
"not",
|
|
79
|
+
"or",
|
|
80
|
+
"pass",
|
|
54
81
|
"print",
|
|
82
|
+
"raise",
|
|
83
|
+
"return",
|
|
55
84
|
"set",
|
|
85
|
+
"str",
|
|
86
|
+
"True",
|
|
56
87
|
"try",
|
|
57
88
|
"type",
|
|
58
89
|
"typer",
|
|
59
90
|
"while",
|
|
91
|
+
"with",
|
|
92
|
+
"yeild",
|
|
60
93
|
}
|
|
@@ -21,7 +21,6 @@ from openapi_spec_tools.cli.utils import gen_config_from_file
|
|
|
21
21
|
from openapi_spec_tools.cli.utils import init_logging
|
|
22
22
|
from openapi_spec_tools.cli.utils import layout_tree_with_error_handling
|
|
23
23
|
from openapi_spec_tools.cli.utils import open_oas_with_error_handling
|
|
24
|
-
from openapi_spec_tools.constants import LOG_CLASS
|
|
25
24
|
from openapi_spec_tools.layout import DEFAULT_START
|
|
26
25
|
from openapi_spec_tools.layout import LayoutGenerator
|
|
27
26
|
|
|
@@ -61,11 +60,11 @@ def generate_api(
|
|
|
61
60
|
The body-type only applies to functions with a request body. It determines the granularity of
|
|
62
61
|
the function arguments, and the amount of work done to form the body.
|
|
63
62
|
"""
|
|
64
|
-
|
|
63
|
+
init_logging(log_level)
|
|
65
64
|
|
|
66
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
65
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
67
66
|
if layout_file:
|
|
68
|
-
commands = layout_tree_with_error_handling(layout_file, start
|
|
67
|
+
commands = layout_tree_with_error_handling(layout_file, start)
|
|
69
68
|
else:
|
|
70
69
|
layout_gen = LayoutGenerator(oas, prefix=prefix or None)
|
|
71
70
|
commands = layout_gen.generate()
|
|
@@ -76,7 +75,7 @@ def generate_api(
|
|
|
76
75
|
typer.echo("Must specify package_name in arguments or configuration.")
|
|
77
76
|
raise typer.Exit(1)
|
|
78
77
|
|
|
79
|
-
kwargs = {"package_name": package_name, "oas": oas, "
|
|
78
|
+
kwargs = {"package_name": package_name, "oas": oas, "config": config}
|
|
80
79
|
if body_type == BodyType.FLAT:
|
|
81
80
|
generator = FlatApiGenerator(**kwargs)
|
|
82
81
|
elif body_type == BodyType.PROPERTY:
|
|
@@ -33,7 +33,6 @@ from openapi_spec_tools.cli_gen import check_for_missing
|
|
|
33
33
|
from openapi_spec_tools.cli_gen import create_tree_table
|
|
34
34
|
from openapi_spec_tools.cli_gen import find_unreferenced
|
|
35
35
|
from openapi_spec_tools.cli_gen import generate_tree_node
|
|
36
|
-
from openapi_spec_tools.constants import LOG_CLASS
|
|
37
36
|
from openapi_spec_tools.layout import DEFAULT_START
|
|
38
37
|
from openapi_spec_tools.layout import LayoutGenerator
|
|
39
38
|
from openapi_spec_tools.layout import LayoutNode
|
|
@@ -91,11 +90,11 @@ def generate_cli(
|
|
|
91
90
|
Use either `--project-dir` to set both relative code and test directories, or
|
|
92
91
|
set the paths specifically using `--code-dir` and `--test-dir`.
|
|
93
92
|
"""
|
|
94
|
-
|
|
93
|
+
init_logging(log_level)
|
|
95
94
|
|
|
96
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
95
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
97
96
|
if layout_file:
|
|
98
|
-
commands = layout_tree_with_error_handling(layout_file, start
|
|
97
|
+
commands = layout_tree_with_error_handling(layout_file, start)
|
|
99
98
|
|
|
100
99
|
missing = check_for_missing(commands, oas)
|
|
101
100
|
if missing:
|
|
@@ -111,7 +110,7 @@ def generate_cli(
|
|
|
111
110
|
typer.echo("Must specify package_name in arguments or configuration.")
|
|
112
111
|
raise typer.Exit(1)
|
|
113
112
|
|
|
114
|
-
generator = CliGenerator(package_name=package_name, oas=oas,
|
|
113
|
+
generator = CliGenerator(package_name=package_name, oas=oas, config=config)
|
|
115
114
|
|
|
116
115
|
if project_dir:
|
|
117
116
|
code_dir = code_dir or os.path.join(project_dir, generator.package_name)
|
|
@@ -152,9 +151,9 @@ def generate_check_missing(
|
|
|
152
151
|
start: StartPointOption = DEFAULT_START,
|
|
153
152
|
log_level: LogLevelOption = "info",
|
|
154
153
|
) -> None:
|
|
155
|
-
|
|
156
|
-
commands = layout_tree_with_error_handling(layout_file, start=start
|
|
157
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
154
|
+
init_logging(log_level)
|
|
155
|
+
commands = layout_tree_with_error_handling(layout_file, start=start)
|
|
156
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
158
157
|
|
|
159
158
|
missing = check_for_missing(commands, oas)
|
|
160
159
|
if missing:
|
|
@@ -172,9 +171,9 @@ def generate_unreferenced(
|
|
|
172
171
|
full_path: Annotated[bool, typer.Option(help="Use full URL path that included variables")] = False,
|
|
173
172
|
log_level: LogLevelOption = "info",
|
|
174
173
|
) -> None:
|
|
175
|
-
|
|
176
|
-
commands = layout_tree_with_error_handling(layout_file, start=start
|
|
177
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
174
|
+
init_logging(log_level)
|
|
175
|
+
commands = layout_tree_with_error_handling(layout_file, start=start)
|
|
176
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
178
177
|
|
|
179
178
|
unreferenced = find_unreferenced(commands, oas)
|
|
180
179
|
if not unreferenced:
|
|
@@ -241,9 +240,9 @@ def update_layout(
|
|
|
241
240
|
indent: IndentOption = 4,
|
|
242
241
|
log_level: LogLevelOption = "info",
|
|
243
242
|
) -> None:
|
|
244
|
-
logger = init_logging(log_level
|
|
245
|
-
commands = layout_tree_with_error_handling(layout_file, start=start
|
|
246
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
243
|
+
logger = init_logging(log_level)
|
|
244
|
+
commands = layout_tree_with_error_handling(layout_file, start=start)
|
|
245
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
247
246
|
|
|
248
247
|
unreferenced = find_unreferenced(commands, oas)
|
|
249
248
|
if not unreferenced:
|
|
@@ -256,8 +255,8 @@ def update_layout(
|
|
|
256
255
|
# walk the list of unreference operations, and try to fit them in
|
|
257
256
|
for op_id, unref in unreferenced.items():
|
|
258
257
|
parts = path_to_parts(unref.get(OasField.X_PATH), prefix)
|
|
259
|
-
command = generator.suggest_command(unref)
|
|
260
258
|
pagination = generator.get_pagination(unref)
|
|
259
|
+
command = generator.suggest_command(unref, pagination)
|
|
261
260
|
op_node = LayoutNode(command=command, identifier=op_id, pagination=pagination)
|
|
262
261
|
|
|
263
262
|
# attempt to find parent based on path
|
|
@@ -270,7 +269,7 @@ def update_layout(
|
|
|
270
269
|
|
|
271
270
|
parent.children.append(op_node)
|
|
272
271
|
|
|
273
|
-
write_layout_tree(new_file or layout_file, commands,
|
|
272
|
+
write_layout_tree(new_file or layout_file, commands, indent)
|
|
274
273
|
typer.echo(f"\nAdded {len(unreferenced)} operations")
|
|
275
274
|
|
|
276
275
|
|
|
@@ -290,10 +289,10 @@ def show_cli_tree(
|
|
|
290
289
|
] = None,
|
|
291
290
|
log_level: LogLevelOption = "info",
|
|
292
291
|
) -> None:
|
|
293
|
-
|
|
294
|
-
layout = layout_tree_with_error_handling(layout_file, start=start
|
|
295
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
296
|
-
generator = CliGenerator(package_name="", oas=oas
|
|
292
|
+
init_logging(log_level)
|
|
293
|
+
layout = layout_tree_with_error_handling(layout_file, start=start)
|
|
294
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
295
|
+
generator = CliGenerator(package_name="", oas=oas)
|
|
297
296
|
|
|
298
297
|
tree = generate_tree_node(generator, layout)
|
|
299
298
|
if not tree.children:
|
|
@@ -341,9 +340,9 @@ def trim_oas(
|
|
|
341
340
|
ops.update(_operations(sub))
|
|
342
341
|
return ops
|
|
343
342
|
|
|
344
|
-
|
|
345
|
-
layout = layout_tree_with_error_handling(layout_file, start=start
|
|
346
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
343
|
+
init_logging(log_level)
|
|
344
|
+
layout = layout_tree_with_error_handling(layout_file, start=start)
|
|
345
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
347
346
|
updated = deepcopy(oas)
|
|
348
347
|
|
|
349
348
|
operations = _operations(layout)
|
|
@@ -9,7 +9,6 @@ from openapi_spec_tools.cli.arguments import LogLevelOption
|
|
|
9
9
|
from openapi_spec_tools.cli.arguments import OpenApiFilenameArgument
|
|
10
10
|
from openapi_spec_tools.cli.utils import init_logging
|
|
11
11
|
from openapi_spec_tools.cli.utils import open_oas_with_error_handling
|
|
12
|
-
from openapi_spec_tools.constants import LOG_CLASS
|
|
13
12
|
from openapi_spec_tools.utils import map_content_types
|
|
14
13
|
|
|
15
14
|
app = typer.Typer(no_args_is_help=True, short_help="Inspect things related to content-types")
|
|
@@ -22,8 +21,8 @@ def content_type_list(
|
|
|
22
21
|
content_type: Annotated[str | None, typer.Option(help="Only display for specified content type")] = None,
|
|
23
22
|
log_level: LogLevelOption = "info",
|
|
24
23
|
) -> None:
|
|
25
|
-
|
|
26
|
-
spec = open_oas_with_error_handling(filename
|
|
24
|
+
init_logging(log_level)
|
|
25
|
+
spec = open_oas_with_error_handling(filename)
|
|
27
26
|
content = map_content_types(spec)
|
|
28
27
|
|
|
29
28
|
if content_type:
|
|
@@ -25,7 +25,6 @@ from openapi_spec_tools.cli.utils import layout_tree_with_error_handling
|
|
|
25
25
|
from openapi_spec_tools.cli.utils import open_layout_with_error_handling
|
|
26
26
|
from openapi_spec_tools.cli.utils import open_oas_with_error_handling
|
|
27
27
|
from openapi_spec_tools.cli.utils import write_layout_tree
|
|
28
|
-
from openapi_spec_tools.constants import LOG_CLASS
|
|
29
28
|
from openapi_spec_tools.layout import DEFAULT_START
|
|
30
29
|
from openapi_spec_tools.layout import LayoutGenerator
|
|
31
30
|
from openapi_spec_tools.layout import LayoutNode
|
|
@@ -66,8 +65,8 @@ def layout_check_format(
|
|
|
66
65
|
hardcoded: Annotated[bool, typer.Option(help="Check the hardCoded parameters")] = True,
|
|
67
66
|
log_level: LogLevelOption = "info",
|
|
68
67
|
) -> None:
|
|
69
|
-
|
|
70
|
-
data = open_layout_with_error_handling(filename
|
|
68
|
+
init_logging(log_level)
|
|
69
|
+
data = open_layout_with_error_handling(filename)
|
|
71
70
|
|
|
72
71
|
def _dict_to_str(errors: dict[str, str], sep=SEP) -> str:
|
|
73
72
|
return f"{sep}{sep.join([f'{k}: {v}' for k, v in errors.items()])}"
|
|
@@ -151,8 +150,8 @@ def layout_tree(
|
|
|
151
150
|
indent: Annotated[int, typer.Option(min=1, max=10, help="Number of characters of indent")] = 2,
|
|
152
151
|
log_level: LogLevelOption = "info",
|
|
153
152
|
) -> None:
|
|
154
|
-
|
|
155
|
-
tree = layout_tree_with_error_handling(filename, start=start
|
|
153
|
+
init_logging(log_level)
|
|
154
|
+
tree = layout_tree_with_error_handling(filename, start=start)
|
|
156
155
|
if style == TreeFormat.JSON:
|
|
157
156
|
print_json(data=tree.as_dict(sparse=True), indent=indent, sort_keys=False)
|
|
158
157
|
return
|
|
@@ -200,8 +199,8 @@ def layout_operations(
|
|
|
200
199
|
ops.update(_operations(sub))
|
|
201
200
|
return ops
|
|
202
201
|
|
|
203
|
-
|
|
204
|
-
tree = layout_tree_with_error_handling(filename, start=start
|
|
202
|
+
init_logging(log_level)
|
|
203
|
+
tree = layout_tree_with_error_handling(filename, start=start)
|
|
205
204
|
operations = _operations(tree)
|
|
206
205
|
print('\n'.join(sorted(operations)))
|
|
207
206
|
return
|
|
@@ -231,8 +230,8 @@ def layout_suggest(
|
|
|
231
230
|
|
|
232
231
|
* May have some small modules (extra layers), such as `deploy list` instead of a desired `deploy`.
|
|
233
232
|
"""
|
|
234
|
-
|
|
235
|
-
oas = open_oas_with_error_handling(openapi_file
|
|
233
|
+
init_logging(log_level)
|
|
234
|
+
oas = open_oas_with_error_handling(openapi_file)
|
|
236
235
|
config = layout_config_from_file(config_file)
|
|
237
236
|
generator = LayoutGenerator(oas, config=config, prefix=prefix or None)
|
|
238
237
|
node = generator.generate()
|
|
@@ -241,7 +240,7 @@ def layout_suggest(
|
|
|
241
240
|
original = file_to_tree(output_file)
|
|
242
241
|
node = merge(original=original, suggested=node)
|
|
243
242
|
|
|
244
|
-
write_layout_tree(output_file, node,
|
|
243
|
+
write_layout_tree(output_file, node, indent)
|
|
245
244
|
print(f"Wrote {output_file}")
|
|
246
245
|
return
|
|
247
246
|
|
|
@@ -270,14 +269,14 @@ def layout_merge(
|
|
|
270
269
|
log_level: LogLevelOption = "info",
|
|
271
270
|
) -> None:
|
|
272
271
|
"""Merge properties from the source file into the destination file."""
|
|
273
|
-
|
|
274
|
-
source_node = layout_tree_with_error_handling(source_file, start=start
|
|
275
|
-
dest_node = layout_tree_with_error_handling(dest_file, start=start
|
|
272
|
+
init_logging(log_level)
|
|
273
|
+
source_node = layout_tree_with_error_handling(source_file, start=start)
|
|
274
|
+
dest_node = layout_tree_with_error_handling(dest_file, start=start)
|
|
276
275
|
|
|
277
276
|
result = merge_node_properties(properties, source_node, dest_node)
|
|
278
277
|
|
|
279
278
|
out_file = out_file or dest_file
|
|
280
|
-
write_layout_tree(out_file, result,
|
|
279
|
+
write_layout_tree(out_file, result, indent)
|
|
281
280
|
print(f"Wrote {out_file}")
|
|
282
281
|
return
|
|
283
282
|
|
|
@@ -16,7 +16,6 @@ from openapi_spec_tools.cli.utils import open_oas_with_error_handling
|
|
|
16
16
|
from openapi_spec_tools.cli.utils import perform_expansion
|
|
17
17
|
from openapi_spec_tools.cli.utils import remove_dict_prefix
|
|
18
18
|
from openapi_spec_tools.cli.utils import remove_list_prefix
|
|
19
|
-
from openapi_spec_tools.constants import LOG_CLASS
|
|
20
19
|
from openapi_spec_tools.types import OasField
|
|
21
20
|
from openapi_spec_tools.utils import find_references
|
|
22
21
|
from openapi_spec_tools.utils import map_models
|
|
@@ -24,6 +23,7 @@ from openapi_spec_tools.utils import model_filter
|
|
|
24
23
|
from openapi_spec_tools.utils import model_full_name
|
|
25
24
|
from openapi_spec_tools.utils import model_references
|
|
26
25
|
from openapi_spec_tools.utils import models_referenced_by
|
|
26
|
+
from openapi_spec_tools.utils import operation_id
|
|
27
27
|
from openapi_spec_tools.utils import unroll
|
|
28
28
|
|
|
29
29
|
app = typer.Typer(no_args_is_help=True, short_help="Inspect things related to models")
|
|
@@ -40,8 +40,8 @@ def models_list(
|
|
|
40
40
|
] = None,
|
|
41
41
|
log_level: LogLevelOption = "info",
|
|
42
42
|
) -> None:
|
|
43
|
-
|
|
44
|
-
spec = open_oas_with_error_handling(filename
|
|
43
|
+
init_logging(log_level)
|
|
44
|
+
spec = open_oas_with_error_handling(filename)
|
|
45
45
|
|
|
46
46
|
models = map_models(spec.get(OasField.COMPONENTS, {}))
|
|
47
47
|
names = sorted(models.keys())
|
|
@@ -70,8 +70,8 @@ def models_show(
|
|
|
70
70
|
expansion: ExpansionOption = "none",
|
|
71
71
|
log_level: LogLevelOption = "info",
|
|
72
72
|
) -> None:
|
|
73
|
-
|
|
74
|
-
spec = open_oas_with_error_handling(filename
|
|
73
|
+
init_logging(log_level)
|
|
74
|
+
spec = open_oas_with_error_handling(filename)
|
|
75
75
|
|
|
76
76
|
components = spec.get(OasField.COMPONENTS, {})
|
|
77
77
|
models = map_models(components)
|
|
@@ -99,8 +99,8 @@ def models_uses(
|
|
|
99
99
|
model_name: ModelNameArgument,
|
|
100
100
|
log_level: LogLevelOption = "info",
|
|
101
101
|
) -> None:
|
|
102
|
-
|
|
103
|
-
spec = open_oas_with_error_handling(filename
|
|
102
|
+
init_logging(log_level)
|
|
103
|
+
spec = open_oas_with_error_handling(filename)
|
|
104
104
|
|
|
105
105
|
models = map_models(spec.get(OasField.COMPONENTS, {}))
|
|
106
106
|
full_name = model_full_name(models, model_name)
|
|
@@ -128,8 +128,8 @@ def models_used_by(
|
|
|
128
128
|
model_name: ModelNameArgument,
|
|
129
129
|
log_level: LogLevelOption = "info",
|
|
130
130
|
) -> None:
|
|
131
|
-
|
|
132
|
-
spec = open_oas_with_error_handling(filename
|
|
131
|
+
init_logging(log_level)
|
|
132
|
+
spec = open_oas_with_error_handling(filename)
|
|
133
133
|
|
|
134
134
|
models = map_models(spec.get(OasField.COMPONENTS, {}))
|
|
135
135
|
full_name = model_full_name(models, model_name)
|
|
@@ -155,8 +155,8 @@ def models_operations(
|
|
|
155
155
|
model_name: ModelNameArgument,
|
|
156
156
|
log_level: LogLevelOption = "info",
|
|
157
157
|
) -> None:
|
|
158
|
-
|
|
159
|
-
spec = open_oas_with_error_handling(filename
|
|
158
|
+
init_logging(log_level)
|
|
159
|
+
spec = open_oas_with_error_handling(filename)
|
|
160
160
|
|
|
161
161
|
models = map_models(spec.get(OasField.COMPONENTS, {}))
|
|
162
162
|
full_name = model_full_name(models, model_name)
|
|
@@ -167,13 +167,13 @@ def models_operations(
|
|
|
167
167
|
model_refs.add(full_name) # include the direct references, too
|
|
168
168
|
|
|
169
169
|
matches = []
|
|
170
|
-
for path_data in spec.get(OasField.PATHS, {}).
|
|
170
|
+
for path, path_data in spec.get(OasField.PATHS, {}).items():
|
|
171
171
|
for method, op_data in path_data.items():
|
|
172
172
|
if method == OasField.PARAMS:
|
|
173
173
|
continue
|
|
174
174
|
references = find_references(op_data)
|
|
175
175
|
if references.intersection(model_refs):
|
|
176
|
-
op_id = op_data
|
|
176
|
+
op_id = operation_id(op_data, method, path)
|
|
177
177
|
matches.append(op_id)
|
|
178
178
|
|
|
179
179
|
matches = remove_list_prefix(matches)
|