openapi-spec-tools 0.16.0__tar.gz → 0.17.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.
Files changed (45) hide show
  1. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/PKG-INFO +1 -1
  2. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/_environment.py +2 -3
  3. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/api_generator.py +5 -6
  4. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/_logging.py +2 -3
  5. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/_requests.py +20 -21
  6. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/base_generator.py +8 -9
  7. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/arguments.py +5 -6
  8. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/cli_gen.py +6 -7
  9. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/history.py +7 -8
  10. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/layout.py +8 -0
  11. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/oas.py +8 -9
  12. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/_arguments.py +2 -3
  13. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/_tree.py +10 -11
  14. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/cli_generator.py +42 -12
  15. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/layout/layout_generator.py +12 -14
  16. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/layout/types.py +19 -10
  17. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/layout/utils.py +62 -3
  18. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/utils.py +5 -7
  19. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/pyproject.toml +1 -1
  20. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_cli_generator.py +101 -35
  21. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/LICENSE +0 -0
  22. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/README.md +0 -0
  23. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/__init__.py +0 -0
  24. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/files.py +0 -0
  25. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/flat_generator.py +0 -0
  26. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/opaque_generator.py +0 -0
  27. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/api_gen/property_generator.py +0 -0
  28. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/constants.py +0 -0
  29. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/files.py +0 -0
  30. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/base_gen/utils.py +0 -0
  31. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/api_gen.py +0 -0
  32. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli/utils.py +0 -0
  33. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/_display.py +0 -0
  34. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/_exceptions.py +0 -0
  35. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/constants.py +0 -0
  36. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/cli_gen/files.py +0 -0
  37. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/layout/merge.py +0 -0
  38. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/openapi_spec_tools/types.py +0 -0
  39. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/__init__.py +0 -0
  40. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/helpers.py +0 -0
  41. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_display.py +0 -0
  42. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_exceptions.py +0 -0
  43. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_files.py +0 -0
  44. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_main.py +0 -0
  45. {openapi_spec_tools-0.16.0 → openapi_spec_tools-0.17.0}/tests/cli_gen/test_tree.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openapi-spec-tools
3
- Version: 0.16.0
3
+ Version: 0.17.0
4
4
  Summary: OpenAPI specification tools for analyzing, updating, and generating a CLI.
5
5
  License-File: LICENSE
6
6
  Author: Rick Porter
@@ -1,8 +1,7 @@
1
1
  import os
2
- from typing import Optional
3
2
 
4
3
 
5
- def env_string(varname: str, default: Optional[str] = None, except_missing: bool = False) -> Optional[str]:
4
+ def env_string(varname: str, default: str | None = None, except_missing: bool = False) -> str | None:
6
5
  value = os.environ.get(varname)
7
6
  if value is not None:
8
7
  return value
@@ -11,7 +10,7 @@ def env_string(varname: str, default: Optional[str] = None, except_missing: bool
11
10
  return default
12
11
 
13
12
 
14
- def env_int(varname: str, default: Optional[int] = None, except_missing: bool = False) -> Optional[int]:
13
+ def env_int(varname: str, default: int | None = None, except_missing: bool = False) -> int | None:
15
14
  value = os.environ.get(varname)
16
15
  if value is not None:
17
16
  return int(value)
@@ -95,7 +95,6 @@ from datetime import date # noqa: F401
95
95
  from datetime import datetime # noqa: F401
96
96
  from enum import Enum # noqa: F401
97
97
  from typing import Any
98
- from typing import Optional # noqa: F401
99
98
 
100
99
  from {self.package_name} import _environment as _e # noqa: F401
101
100
  from {self.package_name} import _logging as _l # noqa: F401
@@ -132,10 +131,10 @@ from {self.package_name} import _requests as _r # noqa: F401
132
131
  )
133
132
  log_help = f'log level, read from {self.env_log_level} if not provided, defaults to {self.default_log}'
134
133
  args = [
135
- f'_api_host: Optional[str] = None, # {host_help}',
136
- f'_api_key: Optional[str] = None, # {key_help}',
137
- f'_api_timeout: Optional[int] = None, # {timeout_help}',
138
- f'_log_level: Optional[str] = None, # {log_help}',
134
+ f'_api_host: str | None = None, # {host_help}',
135
+ f'_api_key: str | None = None, # {key_help}',
136
+ f'_api_timeout: int | None = None, # {timeout_help}',
137
+ f'_log_level: str | None = None, # {log_help}',
139
138
  ]
140
139
  return args
141
140
 
@@ -158,7 +157,7 @@ from {self.package_name} import _requests as _r # noqa: F401
158
157
  arg_default = ""
159
158
  else:
160
159
  if not required:
161
- py_type = f"Optional[{py_type}]"
160
+ py_type = f"{py_type} | None"
162
161
  if schema_default is None:
163
162
  arg_default = " = None"
164
163
  elif collection and not isinstance(schema_default, list):
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  from enum import Enum
3
- from typing import Optional
4
3
 
5
4
  LOG_CLASS = "cli"
6
5
  LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s %(message)s"
@@ -15,11 +14,11 @@ class LogLevel(str, Enum):
15
14
  DEBUG = "debug"
16
15
 
17
16
 
18
- def get_logger(name: Optional[str] = LOG_CLASS) -> logging.Logger:
17
+ def get_logger(name: str | None = LOG_CLASS) -> logging.Logger:
19
18
  return logging.getLogger(name=name)
20
19
 
21
20
 
22
- def init_logging(level: LogLevel, name: Optional[str] = LOG_CLASS) -> logging.Logger:
21
+ def init_logging(level: LogLevel, name: str | None = LOG_CLASS) -> logging.Logger:
23
22
  logging.basicConfig(format=LOG_FORMAT, datefmt=LOG_DATE_FMT)
24
23
  logger = get_logger(name)
25
24
  logger.setLevel(level.upper())
@@ -9,7 +9,6 @@ from copy import deepcopy
9
9
  from datetime import datetime
10
10
  from datetime import timedelta
11
11
  from typing import Any
12
- from typing import Optional
13
12
 
14
13
  import requests
15
14
  import yaml
@@ -65,26 +64,26 @@ class PageParams(BaseModel):
65
64
  """Holds optional pagination parameter names and values."""
66
65
 
67
66
  # page_size_* dictate the limit per request
68
- page_size_value: Optional[int] = None
69
- page_size_name: Optional[str] = None
67
+ page_size_value: int | None = None
68
+ page_size_name: str | None = None
70
69
 
71
70
  # page_start_* dictate the starting point when it is in page increments
72
- page_start_value: Optional[int] = None
73
- page_start_name: Optional[str] = None
71
+ page_start_value: int | None = None
72
+ page_start_name: str | None = None
74
73
 
75
74
  # offset_start_* dictate the starting point when it is specified in item increments
76
- item_start_value: Optional[int] = None
77
- item_start_name: Optional[str] = None
75
+ item_start_value: int | None = None
76
+ item_start_name: str | None = None
78
77
 
79
78
  # max_count specifies the maximim number of items to fetch
80
- max_count: Optional[int] = None
79
+ max_count: int | None = None
81
80
 
82
81
  # items property specifies the property name to pull out the data from
83
- items_property_name: Optional[str] = None
82
+ items_property_name: str | None = None
84
83
 
85
84
  # locations for next url
86
- next_header_name: Optional[str] = None
87
- next_property_name: Optional[str] = None
85
+ next_header_name: str | None = None
86
+ next_property_name: str | None = None
88
87
 
89
88
 
90
89
  def create_url(host_or_base_url: str, *args) -> str:
@@ -104,8 +103,8 @@ def create_url(host_or_base_url: str, *args) -> str:
104
103
 
105
104
 
106
105
  def request_headers(
107
- api_key: Optional[str] = None,
108
- content_type: Optional[str] = None,
106
+ api_key: str | None = None,
107
+ content_type: str | None = None,
109
108
  **kwargs,
110
109
  ) -> dict[str, str]:
111
110
  """Create a set of request headers based on the arguments.
@@ -148,7 +147,7 @@ def raise_for_error(response: requests.Response) -> None:
148
147
  raise requests.HTTPError(message, response=response)
149
148
 
150
149
 
151
- def _pretty_params(params: Optional[dict[str, Any]]) -> str:
150
+ def _pretty_params(params: dict[str, Any] | None) -> str:
152
151
  if not params:
153
152
  return ""
154
153
 
@@ -158,10 +157,10 @@ def _pretty_params(params: Optional[dict[str, Any]]) -> str:
158
157
  def request(
159
158
  method: str,
160
159
  url: str,
161
- headers: Optional[dict[str, Any]] = None,
162
- params: Optional[dict[str, Any]] = None,
163
- body: Optional[dict[str, Any]] = None,
164
- timeout: Optional[int] = None,
160
+ headers: dict[str, Any] | None = None,
161
+ params: dict[str, Any] | None = None,
162
+ body: dict[str, Any] | None = None,
163
+ timeout: int | None = None,
165
164
  **kwargs, # allows passing through additional named parameters
166
165
  ) -> Any:
167
166
  """Perform the specified REST request."""
@@ -213,9 +212,9 @@ def request(
213
212
  def depaginate(
214
213
  page_params: PageParams,
215
214
  url: str,
216
- headers: Optional[dict[str, Any]] = None,
217
- params: Optional[dict[str, Any]] = None,
218
- timeout: Optional[int] = None,
215
+ headers: dict[str, Any] | None = None,
216
+ params: dict[str, Any] | None = None,
217
+ timeout: int | None = None,
219
218
  ) -> Any:
220
219
  """Get a list of items that may be chunked across several pages."""
221
220
  items = []
@@ -3,7 +3,6 @@ import logging
3
3
  import textwrap
4
4
  from copy import deepcopy
5
5
  from typing import Any
6
- from typing import Optional
7
6
 
8
7
  from openapi_spec_tools.base_gen._logging import init_logging
9
8
  from openapi_spec_tools.base_gen.constants import COLLECTIONS
@@ -72,7 +71,7 @@ class BaseGenerator:
72
71
  def __init__(
73
72
  self,
74
73
  oas: dict[str, Any],
75
- logger: Optional[logging.Logger] = None,
74
+ logger: logging.Logger | None = None,
76
75
  supported_content: list[ContentType] = DEFAULT_SUPPORTED_CONTENT,
77
76
  max_help_length: int = DEFAULT_MAX_HELP_LENGTH,
78
77
  reserved: set[str] = DEFAULT_RESERVED,
@@ -277,7 +276,7 @@ class BaseGenerator:
277
276
  """Get the `content` (if any) from the `requestBody`."""
278
277
  return operation.get(OasField.REQ_BODY, {}).get(OasField.CONTENT, {})
279
278
 
280
- def op_get_content_type(self, operation: dict[str, Any]) -> Optional[str]:
279
+ def op_get_content_type(self, operation: dict[str, Any]) -> str | None:
281
280
  """Get the first content-type matching a supported type."""
282
281
  content = self.op_request_content(operation)
283
282
  for ct in self.supported:
@@ -285,7 +284,7 @@ class BaseGenerator:
285
284
  return ct.value
286
285
  return None
287
286
 
288
- def op_request_body(self, operation: dict[str, Any]) -> Optional[dict[str, Any]]:
287
+ def op_request_body(self, operation: dict[str, Any]) -> dict[str, Any] | None:
289
288
  """Get the first request body matching a supported type."""
290
289
  content = self.op_request_content(operation)
291
290
  for ct in self.supported:
@@ -295,7 +294,7 @@ class BaseGenerator:
295
294
 
296
295
  return None
297
296
 
298
- def model_collection_type(self, model: str) -> Optional[str]:
297
+ def model_collection_type(self, model: str) -> str | None:
299
298
  """Determine the collection type (current just an array)."""
300
299
  model_type = self.simplify_type(model.get(OasField.TYPE))
301
300
  if model_type in COLLECTIONS.keys():
@@ -483,7 +482,7 @@ class BaseGenerator:
483
482
 
484
483
  return properties
485
484
 
486
- def schema_to_type(self, schema: str, fmt: Optional[str]) -> Optional[str]:
485
+ def schema_to_type(self, schema: str, fmt: str | None) -> str | None:
487
486
  """Get the base Python type for simple schema types.
488
487
 
489
488
  The fmt is really the "format" field, but renamed to avoid masking builtin.
@@ -528,7 +527,7 @@ class BaseGenerator:
528
527
  return None
529
528
 
530
529
 
531
- def schema_to_pytype(self, schema: dict[str, Any]) -> Optional[str]:
530
+ def schema_to_pytype(self, schema: dict[str, Any]) -> str | None:
532
531
  """Determine the basic Python type from the schema object."""
533
532
  oas_type = self.simplify_type(schema.get(OasField.TYPE))
534
533
  oas_format = schema.get(OasField.FORMAT)
@@ -554,7 +553,7 @@ class BaseGenerator:
554
553
 
555
554
  return None
556
555
 
557
- def get_property_pytype(self, prop_name: str, prop_data: dict[str, Any]) -> Optional[str]:
556
+ def get_property_pytype(self, prop_name: str, prop_data: dict[str, Any]) -> str | None:
558
557
  """Get the "basic" Python type from a property object.
559
558
 
560
559
  Each property potentially has 'type' and 'format' fields.
@@ -577,7 +576,7 @@ class BaseGenerator:
577
576
  if collection:
578
577
  pytype = f"{collection}[{pytype}]"
579
578
  if not prop_data.get(OasField.REQUIRED):
580
- pytype = f"Optional[{pytype}]"
579
+ pytype = f"{pytype} | None"
581
580
 
582
581
  return pytype
583
582
 
@@ -1,7 +1,6 @@
1
1
  """typer argument definitions to improve consistency amongst CLI commands."""
2
2
  from enum import Enum
3
3
  from typing import Annotated
4
- from typing import Optional
5
4
 
6
5
  import typer
7
6
  from rich_objects import OutputFormat
@@ -21,11 +20,11 @@ class LogLevel(str, Enum):
21
20
 
22
21
 
23
22
  CodeDirectoryOption = Annotated[
24
- Optional[str],
23
+ str | None,
25
24
  typer.Option("--code-dir", metavar=DIRECTORY, show_default=False, help="Directory for code -- overrides default")
26
25
  ]
27
26
  CopyrightFileOption = Annotated[
28
- Optional[str],
27
+ str | None,
29
28
  typer.Option(
30
29
  "--copyright-file",
31
30
  metavar=FILENAME,
@@ -47,7 +46,7 @@ LayoutFilenameArgument = Annotated[
47
46
  typer.Argument(metavar=FILENAME, show_default=False, help="Layout file YAML definition"),
48
47
  ]
49
48
  LayoutFilenameOption = Annotated[
50
- Optional[str],
49
+ str | None,
51
50
  typer.Option(
52
51
  "--layout-file",
53
52
  metavar=FILENAME,
@@ -64,7 +63,7 @@ LogLevelOption = Annotated[
64
63
  ),
65
64
  ]
66
65
  MaxCountOption = Annotated[
67
- Optional[int],
66
+ int | None,
68
67
  typer.Option(
69
68
  "--max",
70
69
  "--max-count",
@@ -98,7 +97,7 @@ PathPrefixOption = Annotated[
98
97
  ]
99
98
  StartPointOption = Annotated[str, typer.Option("--start", metavar="START", help="Start point for CLI in layout file")]
100
99
  UpdatedOpenApiFilenameOption = Annotated[
101
- Optional[str],
100
+ str | None,
102
101
  typer.Option(
103
102
  "--updated-file",
104
103
  metavar=FILENAME,
@@ -5,7 +5,6 @@ from copy import deepcopy
5
5
  from pathlib import Path
6
6
  from typing import Annotated
7
7
  from typing import Any
8
- from typing import Optional
9
8
 
10
9
  import typer
11
10
  import yaml
@@ -80,12 +79,12 @@ def generate_cli(
80
79
  package_name: PackageNameArgument,
81
80
  layout_file: LayoutFilenameOption = None,
82
81
  project_dir: Annotated[
83
- Optional[str],
82
+ str | None,
84
83
  typer.Option(metavar=DIRECTORY, show_default=False, help="Project directory name")
85
84
  ] = None,
86
85
  code_dir: CodeDirectoryOption = None,
87
86
  test_dir: Annotated[
88
- Optional[str],
87
+ str | None,
89
88
  typer.Option(metavar=DIRECTORY, show_default=False, help="Directory for tests -- overrides default")
90
89
  ] = None,
91
90
  copyright_file: CopyrightFileOption = None,
@@ -222,7 +221,7 @@ def find_parent(
222
221
  operations: dict[str, Any],
223
222
  path_parts: list[str],
224
223
  prefix: str,
225
- ) -> Optional[LayoutNode]:
224
+ ) -> LayoutNode | None:
226
225
  """Find the parent node (if any) where an operation matches the path parts.
227
226
 
228
227
  The LayoutNode's only know the operationId (not the path), so the operations are needed to
@@ -247,7 +246,7 @@ def update_layout(
247
246
  layout_file: LayoutFilenameArgument,
248
247
  openapi_file: OpenApiFilenameArgument,
249
248
  new_file: Annotated[
250
- Optional[str],
249
+ str | None,
251
250
  typer.Option(metavar="FILENAME", help="New filename (if different than original)")
252
251
  ] = None,
253
252
  start: StartPointOption = DEFAULT_START,
@@ -299,7 +298,7 @@ def show_cli_tree(
299
298
  ] = TreeDisplay.ALL,
300
299
  max_depth: Annotated[int, typer.Option(metavar="DEPTH", help="Maximum tree depth to show")] = 10,
301
300
  search: Annotated[
302
- Optional[str],
301
+ str | None,
303
302
  typer.Option(metavar="NEEDLE", help="Only show the tree for items with this needle.")
304
303
  ] = None,
305
304
  log_level: LogLevelOption = "info",
@@ -330,7 +329,7 @@ def trim_oas(
330
329
  openapi_file: OpenApiFilenameArgument,
331
330
  updated_file: UpdatedOpenApiFilenameOption = None,
332
331
  remove_properties: Annotated[
333
- Optional[list[str]],
332
+ list[str] | None,
334
333
  typer.Option("--remove", metavar="PROPERTIES", show_default=False, help="List of properties to remove."),
335
334
  ] = None,
336
335
  start: StartPointOption = DEFAULT_START,
@@ -6,7 +6,6 @@ from datetime import timezone
6
6
  from pathlib import Path
7
7
  from typing import Annotated
8
8
  from typing import Any
9
- from typing import Optional
10
9
 
11
10
  import git
12
11
  import typer
@@ -32,7 +31,7 @@ app = typer.Typer(name="history", no_args_is_help=True, short_help="Git history
32
31
 
33
32
 
34
33
  AuthorOption = Annotated[
35
- Optional[str],
34
+ str | None,
36
35
  typer.Option(
37
36
  "--author",
38
37
  metavar="NAME",
@@ -41,11 +40,11 @@ AuthorOption = Annotated[
41
40
  )
42
41
  ]
43
42
  EndDateOption = Annotated[
44
- Optional[datetime],
43
+ datetime | None,
45
44
  typer.Option("--end", show_default=False, help="Date/time of latest commit.")
46
45
  ]
47
46
  StartDateOption = Annotated[
48
- Optional[datetime],
47
+ datetime | None,
49
48
  typer.Option("--start", show_default=False, help="Date/time of first commit.")
50
49
  ]
51
50
 
@@ -102,10 +101,10 @@ def _commithash(hash: str) -> str:
102
101
 
103
102
  def _find_commits(
104
103
  oas_file: str,
105
- start: Optional[datetime] = None,
106
- end: Optional[datetime] = None,
107
- author: Optional[str] = None,
108
- max_count: Optional[int] = None,
104
+ start: datetime | None = None,
105
+ end: datetime | None = None,
106
+ author: str | None = None,
107
+ max_count: int | None = None,
109
108
  ) -> list[git.Commit]:
110
109
  """Get a list of commits for the provided file and parameters."""
111
110
  repo = git.Repo(oas_file, search_parent_directories=True)
@@ -25,6 +25,7 @@ from openapi_spec_tools.layout.layout_generator import LayoutGenerator
25
25
  from openapi_spec_tools.layout.merge import merge
26
26
  from openapi_spec_tools.layout.types import LayoutNode
27
27
  from openapi_spec_tools.layout.utils import DEFAULT_START
28
+ from openapi_spec_tools.layout.utils import check_hardcoded
28
29
  from openapi_spec_tools.layout.utils import check_pagination_definitions
29
30
  from openapi_spec_tools.layout.utils import file_to_tree
30
31
  from openapi_spec_tools.layout.utils import operation_duplicates
@@ -57,6 +58,7 @@ def layout_check_format(
57
58
  op_dups: Annotated[bool, typer.Option(help="Check for duplicate names in sub-commands")] = True,
58
59
  op_order: Annotated[bool, typer.Option(help="Check the operations order within each sub-command")] = True,
59
60
  pagination: Annotated[bool, typer.Option(help="Check the pagination parameters for issues")] = True,
61
+ hardcoded: Annotated[bool, typer.Option(help="Check the hardCoded parameters")] = True,
60
62
  log_level: LogLevelOption = "info",
61
63
  ) -> None:
62
64
  logger = init_logging(log_level, LOG_CLASS)
@@ -106,6 +108,12 @@ def layout_check_format(
106
108
  typer.echo(f"Pagination parameter errors:{_dict_to_str(errors)}")
107
109
  result = 1
108
110
 
111
+ if hardcoded:
112
+ errors = check_hardcoded(data)
113
+ if errors:
114
+ typer.echo(f"Hardcoded parameter errors:{_dict_to_str(errors)}")
115
+ result = 1
116
+
109
117
  if result:
110
118
  raise typer.Exit(result)
111
119
 
@@ -5,7 +5,6 @@ from enum import Enum
5
5
  from pathlib import Path
6
6
  from typing import Annotated
7
7
  from typing import Any
8
- from typing import Optional
9
8
 
10
9
  import typer
11
10
  import yaml
@@ -180,15 +179,15 @@ def update(
180
179
  ] = False,
181
180
  remove_all_tags: Annotated[bool, typer.Option(help="Remove all tags")] = False,
182
181
  remove_operations: Annotated[
183
- Optional[list[str]],
182
+ list[str] | None,
184
183
  typer.Option("--remove-op", show_default=False, help="List of operations to remove"),
185
184
  ] = None,
186
185
  allowed_operations: Annotated[
187
- Optional[list[str]],
186
+ list[str] | None,
188
187
  typer.Option("--allow-op", show_default=False, help="List of operations to keep"),
189
188
  ] = None,
190
189
  remove_properties: Annotated[
191
- Optional[list[str]],
190
+ list[str] | None,
192
191
  typer.Option("--remove", show_default=False, help="List of properties to remove."),
193
192
  ] = None,
194
193
  display_option: Annotated[
@@ -261,7 +260,7 @@ analyze_typer.add_typer(op_typer, name="ops")
261
260
  def operation_list(
262
261
  filename: OpenApiFilenameArgument,
263
262
  search: Annotated[
264
- Optional[str],
263
+ str | None,
265
264
  typer.Option("--contains", help="Search for this value in the operation names"),
266
265
  ] = None,
267
266
  log_level: LogLevelOption = "info",
@@ -349,7 +348,7 @@ def operation_models(
349
348
  path_typer = typer.Typer(no_args_is_help=True, short_help="Inspect things related to paths")
350
349
  analyze_typer.add_typer(path_typer, name="paths")
351
350
 
352
- PathSearchOption = Annotated[Optional[str], typer.Option("--contains", help="Search for this value in the path")]
351
+ PathSearchOption = Annotated[str | None, typer.Option("--contains", help="Search for this value in the path")]
353
352
  PathSubpathOption = Annotated[
354
353
  bool,
355
354
  typer.Option("--sub-paths", help="Include sub-paths of the search value"),
@@ -454,7 +453,7 @@ analyze_typer.add_typer(models_typer, name="models")
454
453
  def models_list(
455
454
  filename: OpenApiFilenameArgument,
456
455
  search: Annotated[
457
- Optional[str],
456
+ str | None,
458
457
  typer.Option("--contains", help="Search for this value in the model names"),
459
458
  ] = None,
460
459
  log_level: LogLevelOption = "info",
@@ -608,7 +607,7 @@ analyze_typer.add_typer(tag_typer, name="tags")
608
607
  @tag_typer.command(name="list", short_help="List tags in OpenAPI spec")
609
608
  def tags_list(
610
609
  filename: OpenApiFilenameArgument,
611
- search: Annotated[Optional[str], typer.Option("--contains", help="Search for this value in the tag names")] = None,
610
+ search: Annotated[str | None, typer.Option("--contains", help="Search for this value in the tag names")] = None,
612
611
  log_level: LogLevelOption = "info",
613
612
  ) -> None:
614
613
  logger = init_logging(log_level, LOG_CLASS)
@@ -685,7 +684,7 @@ analyze_typer.add_typer(content_typer, name="content")
685
684
  def content_type_list(
686
685
  filename: OpenApiFilenameArgument,
687
686
  max_size: Annotated[int, typer.Option(help="Maximum number of operations to show")] = 10,
688
- content_type: Annotated[Optional[str], typer.Option(help="Only display for specified content type")] = None,
687
+ content_type: Annotated[str | None, typer.Option(help="Only display for specified content type")] = None,
689
688
  log_level: LogLevelOption = "info",
690
689
  ) -> None:
691
690
  logger = init_logging(log_level, LOG_CLASS)
@@ -1,5 +1,4 @@
1
1
  from typing import Annotated
2
- from typing import Optional
3
2
 
4
3
  import typer
5
4
  from rich_objects import OutputFormat
@@ -67,7 +66,7 @@ MaxDepthOption = Annotated[
67
66
  ),
68
67
  ]
69
68
  MaxCountOption = Annotated[
70
- Optional[int],
69
+ int | None,
71
70
  typer.Option(
72
71
  "--max",
73
72
  "--max-count",
@@ -100,7 +99,7 @@ TreeDisplayOption = Annotated[
100
99
  ),
101
100
  ]
102
101
  TreeSearchOption = Annotated[
103
- Optional[str],
102
+ str | None,
104
103
  typer.Option(
105
104
  "--search",
106
105
  help="Value to look for in command info."
@@ -1,5 +1,4 @@
1
1
  from enum import Enum
2
- from typing import Optional
3
2
 
4
3
  import yaml
5
4
  from pydantic import BaseModel
@@ -41,11 +40,11 @@ class TreeNode(BaseModel):
41
40
  """
42
41
 
43
42
  name: str
44
- help: Optional[str] = None
45
- operation: Optional[str] = None
46
- function: Optional[str] = None
47
- method: Optional[str] = None
48
- path: Optional[str] = None
43
+ help: str | None = None
44
+ operation: str | None = None
45
+ function: str | None = None
46
+ method: str | None = None
47
+ path: str | None = None
49
48
  children: list["TreeNode"] = Field(default_factory=list)
50
49
 
51
50
  def get(self, display: TreeDisplay) -> str:
@@ -61,7 +60,7 @@ class TreeNode(BaseModel):
61
60
 
62
61
  def contains(self, needle: str) -> bool:
63
62
  """Check if the needle is found in this node, or any children."""
64
- def _has_needle(value: Optional[str]) -> bool:
63
+ def _has_needle(value: str | None) -> bool:
65
64
  return value and needle in value
66
65
 
67
66
  if any(_has_needle(p) for p in [self.name, self.help, self.function, self.operation, self.path, self.method]):
@@ -73,7 +72,7 @@ class TreeNode(BaseModel):
73
72
  return False
74
73
 
75
74
 
76
- def parse_tree(identifier: str, command: str, data: dict[str, dict]) -> Optional[TreeNode]:
75
+ def parse_tree(identifier: str, command: str, data: dict[str, dict]) -> TreeNode | None:
77
76
  """Parse the specified file into a tree."""
78
77
  item = data.get(identifier)
79
78
  children = []
@@ -134,7 +133,7 @@ def add_node_to_table(
134
133
  display: TreeDisplay,
135
134
  depth: int,
136
135
  max_depth: int,
137
- needle: Optional[str],
136
+ needle: str | None,
138
137
  ) -> None:
139
138
  """Add a node (with children) to the table."""
140
139
  indent = INDENT * depth
@@ -158,7 +157,7 @@ def create_tree_table(
158
157
  node: TreeNode,
159
158
  display: TreeDisplay,
160
159
  max_depth: int,
161
- needle: Optional[str] = None,
160
+ needle: str | None = None,
162
161
  ) -> Table:
163
162
  """Create the tree table.
164
163
 
@@ -189,7 +188,7 @@ def create_tree_table(
189
188
  return table
190
189
 
191
190
 
192
- def tree(filename: str, identifier: str, display: TreeDisplay, max_depth: int, needle: Optional[str] = None) -> None:
191
+ def tree(filename: str, identifier: str, display: TreeDisplay, max_depth: int, needle: str | None = None) -> None:
193
192
  """Print the tree table for the specified command."""
194
193
  with open(filename, "r", encoding="utf-8", newline="\n") as fp:
195
194
  data = yaml.safe_load(fp)