Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 2f59770

Browse files
committed
Add fallback overload and Fix api_client type
1 parent a4507c0 commit 2f59770

File tree

115 files changed

+5431
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+5431
-456
lines changed

modules/openapi-json-schema-generator/src/main/resources/python/api_client.handlebars

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,15 @@ class JSONDetector:
812812
return True
813813
return False
814814

815+
Response_T = typing.TypeVar("Response_T", bound=ApiResponse)
815816

816817
class OpenApiResponse(JSONDetector):
817818
__filename_content_disposition_pattern = re.compile('filename="(.+?)"')
819+
response_cls: typing.Type[Response_T]
818820

819821
def __init__(
820822
self,
821-
response_cls: typing.Type[ApiResponse] = ApiResponse,
823+
response_cls: typing.Type[Response_T] = ApiResponse,
822824
content: typing.Optional[typing.Dict[str, MediaType]] = None,
823825
headers: typing.Optional[typing.List[HeaderParameter]] = None,
824826
):
@@ -903,7 +905,7 @@ class OpenApiResponse(JSONDetector):
903905
for part in msg.get_payload()
904906
}
905907

906-
def deserialize(self, response: urllib3.HTTPResponse, configuration: Configuration) -> ApiResponse:
908+
def deserialize(self, response: urllib3.HTTPResponse, configuration: Configuration) -> Response_T:
907909
content_type = response.getheader('content-type')
908910
deserialized_body = unset
909911
streamed = response.supports_chunked_reads()

modules/openapi-json-schema-generator/src/main/resources/python/endpoint.handlebars

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ class BaseApi(api_client.Api):
394394
def _{{operationId}}_oapg(
395395
{{> endpoint_args_overload selfType="api_client.Api" isSkip=true}}
396396

397+
@typing.overload
398+
def _{{operationId}}_oapg(
399+
{{> endpoint_args selfType="api_client.Api" }}
400+
...
401+
397402
def _{{operationId}}_oapg(
398403
{{> endpoint_args selfType="api_client.Api" }}
399404
"""
@@ -543,11 +548,16 @@ class {{operationIdCamelCase}}(BaseApi):
543548

544549
@typing.overload
545550
def {{operationId}}(
546-
{{> endpoint_args_overload selfType="api_client.Api" isSkip=false}}
551+
{{> endpoint_args_overload selfType="BaseApi" isSkip=false}}
547552

548553
@typing.overload
549554
def {{operationId}}(
550-
{{> endpoint_args_overload selfType="api_client.Api" isSkip=true}}
555+
{{> endpoint_args_overload selfType="BaseApi" isSkip=true}}
556+
557+
@typing.overload
558+
def {{operationId}}(
559+
{{> endpoint_args selfType="BaseApi" }}
560+
...
551561

552562
def {{operationId}}(
553563
{{> endpoint_args selfType="BaseApi" }}
@@ -561,11 +571,16 @@ class ApiFor{{httpMethod}}(BaseApi):
561571

562572
@typing.overload
563573
def {{httpMethod}}(
564-
{{> endpoint_args_overload selfType="api_client.Api" isSkip=false}}
574+
{{> endpoint_args_overload selfType="BaseApi" isSkip=false}}
565575

566576
@typing.overload
567577
def {{httpMethod}}(
568-
{{> endpoint_args_overload selfType="api_client.Api" isSkip=true}}
578+
{{> endpoint_args_overload selfType="BaseApi" isSkip=true}}
579+
580+
@typing.overload
581+
def {{httpMethod}}(
582+
{{> endpoint_args selfType="BaseApi" }}
583+
...
569584

570585
def {{httpMethod}}(
571586
{{> endpoint_args selfType="BaseApi" }}

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,15 @@ def _content_type_is_json(cls, content_type: str) -> bool:
816816
return True
817817
return False
818818

819+
Response_T = typing.TypeVar("Response_T", bound=ApiResponse)
819820

820821
class OpenApiResponse(JSONDetector):
821822
__filename_content_disposition_pattern = re.compile('filename="(.+?)"')
823+
response_cls: typing.Type[Response_T]
822824

823825
def __init__(
824826
self,
825-
response_cls: typing.Type[ApiResponse] = ApiResponse,
827+
response_cls: typing.Type[Response_T] = ApiResponse,
826828
content: typing.Optional[typing.Dict[str, MediaType]] = None,
827829
headers: typing.Optional[typing.List[HeaderParameter]] = None,
828830
):
@@ -907,7 +909,7 @@ def __deserialize_multipart_form_data(
907909
for part in msg.get_payload()
908910
}
909911

910-
def deserialize(self, response: urllib3.HTTPResponse, configuration: Configuration) -> ApiResponse:
912+
def deserialize(self, response: urllib3.HTTPResponse, configuration: Configuration) -> Response_T:
911913
content_type = response.getheader('content-type')
912914
deserialized_body = unset
913915
streamed = response.supports_chunked_reads()

samples/openapi3/client/petstore/python/petstore_api/paths/another_fake_dummy/patch.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ def _call_123_test_special_tags_oapg(
9595
) -> api_client.ApiResponseWithoutDeserialization:
9696
...
9797

98+
@typing.overload
99+
def _call_123_test_special_tags_oapg(
100+
self: api_client.Api,
101+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
102+
content_type: str = 'application/json',
103+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
104+
stream: bool = False,
105+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
106+
skip_deserialization: bool = False,
107+
) -> typing.Union[
108+
api_client.ApiResponse,
109+
api_client.ApiResponseWithoutDeserialization
110+
]:
111+
...
112+
98113
def _call_123_test_special_tags_oapg(
99114
self: api_client.Api,
100115
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
@@ -162,7 +177,7 @@ class Call123TestSpecialTags(BaseApi):
162177

163178
@typing.overload
164179
def call_123_test_special_tags(
165-
self: api_client.Api,
180+
self: BaseApi,
166181
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
167182
content_type: str = 'application/json',
168183
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -176,7 +191,7 @@ def call_123_test_special_tags(
176191

177192
@typing.overload
178193
def call_123_test_special_tags(
179-
self: api_client.Api,
194+
self: BaseApi,
180195
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
181196
content_type: str = 'application/json',
182197
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -186,6 +201,21 @@ def call_123_test_special_tags(
186201
) -> api_client.ApiResponseWithoutDeserialization:
187202
...
188203

204+
@typing.overload
205+
def call_123_test_special_tags(
206+
self: BaseApi,
207+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
208+
content_type: str = 'application/json',
209+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
210+
stream: bool = False,
211+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
212+
skip_deserialization: bool = False,
213+
) -> typing.Union[
214+
api_client.ApiResponse,
215+
api_client.ApiResponseWithoutDeserialization
216+
]:
217+
...
218+
189219
def call_123_test_special_tags(
190220
self: BaseApi,
191221
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
@@ -213,7 +243,7 @@ class ApiForpatch(BaseApi):
213243

214244
@typing.overload
215245
def patch(
216-
self: api_client.Api,
246+
self: BaseApi,
217247
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
218248
content_type: str = 'application/json',
219249
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -227,7 +257,7 @@ def patch(
227257

228258
@typing.overload
229259
def patch(
230-
self: api_client.Api,
260+
self: BaseApi,
231261
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
232262
content_type: str = 'application/json',
233263
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -237,6 +267,21 @@ def patch(
237267
) -> api_client.ApiResponseWithoutDeserialization:
238268
...
239269

270+
@typing.overload
271+
def patch(
272+
self: BaseApi,
273+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
274+
content_type: str = 'application/json',
275+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
276+
stream: bool = False,
277+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
278+
skip_deserialization: bool = False,
279+
) -> typing.Union[
280+
api_client.ApiResponse,
281+
api_client.ApiResponseWithoutDeserialization
282+
]:
283+
...
284+
240285
def patch(
241286
self: BaseApi,
242287
body: typing.Union[SchemaForRequestBodyApplicationJson, ],

samples/openapi3/client/petstore/python/petstore_api/paths/another_fake_dummy/patch.pyi

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ class BaseApi(api_client.Api):
6363
) -> api_client.ApiResponseWithoutDeserialization:
6464
...
6565

66+
@typing.overload
67+
def _call_123_test_special_tags_oapg(
68+
self: api_client.Api,
69+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
70+
content_type: str = 'application/json',
71+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
72+
stream: bool = False,
73+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
74+
skip_deserialization: bool = False,
75+
) -> typing.Union[
76+
api_client.ApiResponse,
77+
api_client.ApiResponseWithoutDeserialization
78+
]:
79+
...
80+
6681
def _call_123_test_special_tags_oapg(
6782
self: api_client.Api,
6883
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
@@ -130,7 +145,7 @@ class Call123TestSpecialTags(BaseApi):
130145

131146
@typing.overload
132147
def call_123_test_special_tags(
133-
self: api_client.Api,
148+
self: BaseApi,
134149
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
135150
content_type: str = 'application/json',
136151
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -144,7 +159,7 @@ class Call123TestSpecialTags(BaseApi):
144159

145160
@typing.overload
146161
def call_123_test_special_tags(
147-
self: api_client.Api,
162+
self: BaseApi,
148163
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
149164
content_type: str = 'application/json',
150165
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -154,6 +169,21 @@ class Call123TestSpecialTags(BaseApi):
154169
) -> api_client.ApiResponseWithoutDeserialization:
155170
...
156171

172+
@typing.overload
173+
def call_123_test_special_tags(
174+
self: BaseApi,
175+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
176+
content_type: str = 'application/json',
177+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
178+
stream: bool = False,
179+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
180+
skip_deserialization: bool = False,
181+
) -> typing.Union[
182+
api_client.ApiResponse,
183+
api_client.ApiResponseWithoutDeserialization
184+
]:
185+
...
186+
157187
def call_123_test_special_tags(
158188
self: BaseApi,
159189
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
@@ -181,7 +211,7 @@ class ApiForpatch(BaseApi):
181211

182212
@typing.overload
183213
def patch(
184-
self: api_client.Api,
214+
self: BaseApi,
185215
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
186216
content_type: str = 'application/json',
187217
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -195,7 +225,7 @@ class ApiForpatch(BaseApi):
195225

196226
@typing.overload
197227
def patch(
198-
self: api_client.Api,
228+
self: BaseApi,
199229
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
200230
content_type: str = 'application/json',
201231
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
@@ -205,6 +235,21 @@ class ApiForpatch(BaseApi):
205235
) -> api_client.ApiResponseWithoutDeserialization:
206236
...
207237

238+
@typing.overload
239+
def patch(
240+
self: BaseApi,
241+
body: typing.Union[SchemaForRequestBodyApplicationJson, ],
242+
content_type: str = 'application/json',
243+
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
244+
stream: bool = False,
245+
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
246+
skip_deserialization: bool = False,
247+
) -> typing.Union[
248+
api_client.ApiResponse,
249+
api_client.ApiResponseWithoutDeserialization
250+
]:
251+
...
252+
208253
def patch(
209254
self: BaseApi,
210255
body: typing.Union[SchemaForRequestBodyApplicationJson, ],

0 commit comments

Comments
 (0)