Skip to content

Commit 4ac8721

Browse files
committed
Add the deprecated attribute to Endpoint class
1 parent 75cb057 commit 4ac8721

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

openapi_python_client/parser/openapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ class Endpoint:
141141
requires_security: bool
142142
tags: list[PythonIdentifier]
143143
summary: str | None = ""
144+
deprecated: bool = False
144145
relative_imports: set[str] = field(default_factory=set)
145146
query_parameters: list[Property] = field(default_factory=list)
146147
path_parameters: list[Property] = field(default_factory=list)
@@ -422,6 +423,7 @@ def from_data(
422423
name=name,
423424
requires_security=bool(data.security),
424425
tags=tags,
426+
deprecated=data.deprecated,
425427
)
426428

427429
result, schemas, parameters = Endpoint.add_parameters(

tests/test_parser/test_openapi.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,38 @@ def test_from_data_no_security(self, mocker, config):
555555
config=config,
556556
)
557557

558+
def test_from_data_deprecated(self, mocker, config):
559+
path = mocker.MagicMock()
560+
method = mocker.MagicMock()
561+
add_parameters = mocker.patch.object(
562+
Endpoint, "add_parameters", return_value=(mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock())
563+
)
564+
mocker.patch.object(Endpoint, "_add_responses", return_value=(mocker.MagicMock(), mocker.MagicMock()))
565+
data = oai.Operation.model_construct(
566+
description=mocker.MagicMock(),
567+
operationId=mocker.MagicMock(),
568+
security={"blah": "bloo"},
569+
responses=mocker.MagicMock(),
570+
deprecated=True,
571+
)
572+
mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description)
573+
574+
Endpoint.from_data(
575+
data=data,
576+
path=path,
577+
method=method,
578+
tags=["default"],
579+
schemas=mocker.MagicMock(),
580+
responses={},
581+
parameters=mocker.MagicMock(),
582+
config=config,
583+
request_bodies={},
584+
)
585+
586+
add_parameters.assert_called_once()
587+
endpoint_arg = add_parameters.call_args.kwargs["endpoint"]
588+
assert endpoint_arg.deprecated is True
589+
558590
def test_from_data_some_bad_bodies(self, config):
559591
endpoint, _, _ = Endpoint.from_data(
560592
data=oai.Operation(

0 commit comments

Comments
 (0)