Skip to content

Commit 10212d5

Browse files
committed
fix: Include JSON body parameters in docstrings when that's the only param.
1 parent a039b99 commit 10212d5

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def sync_detailed(
5959
6060
Try sending a JSON body
6161
62+
Args:
63+
json_body (AModel): A Model for testing all the ways custom objects can be used
64+
6265
Returns:
6366
Response[Union[Any, HTTPValidationError]]
6467
"""
@@ -85,6 +88,9 @@ def sync(
8588
8689
Try sending a JSON body
8790
91+
Args:
92+
json_body (AModel): A Model for testing all the ways custom objects can be used
93+
8894
Returns:
8995
Response[Union[Any, HTTPValidationError]]
9096
"""
@@ -104,6 +110,9 @@ async def asyncio_detailed(
104110
105111
Try sending a JSON body
106112
113+
Args:
114+
json_body (AModel): A Model for testing all the ways custom objects can be used
115+
107116
Returns:
108117
Response[Union[Any, HTTPValidationError]]
109118
"""
@@ -128,6 +137,9 @@ async def asyncio(
128137
129138
Try sending a JSON body
130139
140+
Args:
141+
json_body (AModel): A Model for testing all the ways custom objects can be used
142+
131143
Returns:
132144
Response[Union[Any, HTTPValidationError]]
133145
"""

end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py

+12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def sync_detailed(
5555
) -> Response[Union[HTTPValidationError, str]]:
5656
"""Json Body Which is String
5757
58+
Args:
59+
json_body (str):
60+
5861
Returns:
5962
Response[Union[HTTPValidationError, str]]
6063
"""
@@ -79,6 +82,9 @@ def sync(
7982
) -> Optional[Union[HTTPValidationError, str]]:
8083
"""Json Body Which is String
8184
85+
Args:
86+
json_body (str):
87+
8288
Returns:
8389
Response[Union[HTTPValidationError, str]]
8490
"""
@@ -96,6 +102,9 @@ async def asyncio_detailed(
96102
) -> Response[Union[HTTPValidationError, str]]:
97103
"""Json Body Which is String
98104
105+
Args:
106+
json_body (str):
107+
99108
Returns:
100109
Response[Union[HTTPValidationError, str]]
101110
"""
@@ -118,6 +127,9 @@ async def asyncio(
118127
) -> Optional[Union[HTTPValidationError, str]]:
119128
"""Json Body Which is String
120129
130+
Args:
131+
json_body (str):
132+
121133
Returns:
122134
Response[Union[HTTPValidationError, str]]
123135
"""

end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def sync_detailed(
5353
) -> Response[TestInlineObjectsResponse200]:
5454
"""Test Inline Objects
5555
56+
Args:
57+
json_body (TestInlineObjectsJsonBody):
58+
5659
Returns:
5760
Response[TestInlineObjectsResponse200]
5861
"""
@@ -77,6 +80,9 @@ def sync(
7780
) -> Optional[TestInlineObjectsResponse200]:
7881
"""Test Inline Objects
7982
83+
Args:
84+
json_body (TestInlineObjectsJsonBody):
85+
8086
Returns:
8187
Response[TestInlineObjectsResponse200]
8288
"""
@@ -94,6 +100,9 @@ async def asyncio_detailed(
94100
) -> Response[TestInlineObjectsResponse200]:
95101
"""Test Inline Objects
96102
103+
Args:
104+
json_body (TestInlineObjectsJsonBody):
105+
97106
Returns:
98107
Response[TestInlineObjectsResponse200]
99108
"""
@@ -116,6 +125,9 @@ async def asyncio(
116125
) -> Optional[TestInlineObjectsResponse200]:
117126
"""Test Inline Objects
118127
128+
Args:
129+
json_body (TestInlineObjectsJsonBody):
130+
119131
Returns:
120132
Response[TestInlineObjectsResponse200]
121133
"""

openapi_python_client/parser/openapi.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def response_type(self) -> str:
416416
return self.responses[0].prop.get_type_string()
417417
return f"Union[{', '.join(types)}]"
418418

419-
def all_parameters(self) -> Iterator[Property]:
419+
def iter_all_parameters(self) -> Iterator[Property]:
420420
"""Iterate through all the parameters of this endpoint"""
421421
yield from self.path_parameters.values()
422422
yield from self.query_parameters.values()
@@ -427,6 +427,10 @@ def all_parameters(self) -> Iterator[Property]:
427427
if self.json_body:
428428
yield self.json_body
429429

430+
def list_all_parameters(self) -> List[Property]:
431+
"""Return a List of all the parameters of this endpoint"""
432+
return list(self.iter_all_parameters())
433+
430434

431435
@dataclass
432436
class GeneratorData:

openapi_python_client/templates/endpoint_macros.py.jinja

+3-2
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ json_body=json_body,
159159
{# Leave extra space so that Args or Returns isn't at the top #}
160160

161161
{% endif %}
162-
{% if endpoint.path_parameters or endpoint.query_parameters or endpoint.header_parameters or endpoint.cookie_parameters %}
162+
{% set all_parameters = endpoint.list_all_parameters() %}
163+
{% if all_parameters %}
163164
Args:
164-
{% for parameter in endpoint.all_parameters() %}
165+
{% for parameter in all_parameters %}
165166
{{ parameter.to_docstring() | wordwrap(90) | indent(8) }}
166167
{% endfor %}
167168

0 commit comments

Comments
 (0)