Skip to content
This repository was archived by the owner on Jun 2, 2026. It is now read-only.

Commit 4c9c26c

Browse files
committed
Refine CLI annotation mapping for Python 3.9
1 parent 257d55d commit 4c9c26c

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

defectdojo_api_generated/cli/commands/apis.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ def _get_click_type(
197197

198198

199199
def _get_class_annotation(click_type: Any) -> type:
200-
# Classyclick inspects annotations at import time and expects a runtime type,
201-
# not typing.Any or a ParamType instance such as click.Path(...).
202-
if click_type is Any or isinstance(click_type, click.ParamType):
200+
# Classyclick inspects annotations at import time and expects a runtime type.
201+
if click_type is Any:
203202
return str
203+
if isinstance(click_type, click.Path):
204+
return Path
204205
return click_type
205206

206207

tests/unit/test_cli.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44
from importlib.metadata import version
55
from pathlib import Path
6-
from typing import Any, Optional
6+
from typing import Any, Optional, Tuple, Union
77
from unittest import mock
88

99
from click.testing import CliRunner
@@ -303,6 +303,24 @@ def create(self, any_request: AnyRequest):
303303

304304
self.assertEqual(option.type.name, 'text')
305305

306+
def test_request_model_file_fields_annotate_as_path(self):
307+
class FileRequest(BaseModel):
308+
file: Optional[Union[bytes, str, Tuple[str, bytes]]] = None
309+
310+
class FileRequestApi:
311+
def __init__(self, api_client):
312+
self.api_client = api_client
313+
314+
def create(self, file_request: FileRequest):
315+
return file_request.model_dump()
316+
317+
command_class = make_api_group('file_request_api', FileRequestApi)
318+
command = command_class.click
319+
option = next(param for param in command.params if getattr(param, 'name', None) == 'file')
320+
321+
self.assertIs(command_class.__annotations__['file'], Path)
322+
self.assertEqual(option.type.name, 'file')
323+
306324
def test_bad_request_exception_uses_detail_message(self):
307325
runner = CliRunner()
308326

0 commit comments

Comments
 (0)