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

Commit 226f539

Browse files
committed
Handles all errors response corner case in endpoint response type hint
1 parent 2987565 commit 226f539

File tree

13 files changed

+37
-92
lines changed

13 files changed

+37
-92
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/CodegenOperation.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ public boolean getHasDefaultResponse() {
193193
return responses.stream().anyMatch(response -> response.isDefault);
194194
}
195195

196+
public boolean getAllResponsesAreErrors() {
197+
return responses.stream().allMatch(response -> response.is4xx || response.is5xx);
198+
}
199+
196200
/**
197201
* Check if there's at least one vendor extension
198202
*

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
) -> api_client.ApiResponseWithoutDeserialization: ...
4949
{{/eq}}
5050
{{#eq skipDeserialization "False"}}
51-
) -> typing.Union[
51+
) -> {{#if getAllResponsesAreErrors}}api_client.ApiResponseWithoutDeserialization: ...{{else}}typing.Union[
5252
{{#each responses}}
5353
{{#if isDefault}}
5454
ApiResponseForDefault,
@@ -59,6 +59,7 @@
5959
{{/if}}
6060
{{/each}}
6161
]: ...
62+
{{/if}}
6263
{{/eq}}
6364
{{#eq skipDeserialization "null"}}
6465
{{#if isOverload}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.9
1+
unset

samples/openapi3/client/petstore/python/petstore_api/paths/pet/put.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ def _update_pet_oapg(
111111
stream: bool = False,
112112
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
113113
skip_deserialization: typing_extensions.Literal[False] = False,
114-
) -> typing.Union[
115-
]: ...
116-
114+
) -> api_client.ApiResponseWithoutDeserialization: ...
117115
@typing.overload
118116
def _update_pet_oapg(
119117
self,
@@ -210,9 +208,7 @@ def update_pet(
210208
stream: bool = False,
211209
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
212210
skip_deserialization: typing_extensions.Literal[False] = False,
213-
) -> typing.Union[
214-
]: ...
215-
211+
) -> api_client.ApiResponseWithoutDeserialization: ...
216212
@typing.overload
217213
def update_pet(
218214
self,
@@ -268,9 +264,7 @@ def put(
268264
stream: bool = False,
269265
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
270266
skip_deserialization: typing_extensions.Literal[False] = False,
271-
) -> typing.Union[
272-
]: ...
273-
267+
) -> api_client.ApiResponseWithoutDeserialization: ...
274268
@typing.overload
275269
def put(
276270
self,

samples/openapi3/client/petstore/python/petstore_api/paths/pet/put.pyi

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ class BaseApi(api_client.Api):
9090
stream: bool = False,
9191
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
9292
skip_deserialization: typing_extensions.Literal[False] = False,
93-
) -> typing.Union[
94-
]: ...
95-
93+
) -> api_client.ApiResponseWithoutDeserialization: ...
9694
@typing.overload
9795
def _update_pet_oapg(
9896
self,
@@ -189,9 +187,7 @@ class UpdatePet(BaseApi):
189187
stream: bool = False,
190188
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
191189
skip_deserialization: typing_extensions.Literal[False] = False,
192-
) -> typing.Union[
193-
]: ...
194-
190+
) -> api_client.ApiResponseWithoutDeserialization: ...
195191
@typing.overload
196192
def update_pet(
197193
self,
@@ -247,9 +243,7 @@ class ApiForput(BaseApi):
247243
stream: bool = False,
248244
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
249245
skip_deserialization: typing_extensions.Literal[False] = False,
250-
) -> typing.Union[
251-
]: ...
252-
246+
) -> api_client.ApiResponseWithoutDeserialization: ...
253247
@typing.overload
254248
def put(
255249
self,

samples/openapi3/client/petstore/python/petstore_api/paths/pet_pet_id/delete.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ def _delete_pet_oapg(
108108
stream: bool = False,
109109
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
110110
skip_deserialization: typing_extensions.Literal[False] = False,
111-
) -> typing.Union[
112-
]: ...
113-
111+
) -> api_client.ApiResponseWithoutDeserialization: ...
114112
@typing.overload
115113
def _delete_pet_oapg(
116114
self,
@@ -210,9 +208,7 @@ def delete_pet(
210208
stream: bool = False,
211209
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
212210
skip_deserialization: typing_extensions.Literal[False] = False,
213-
) -> typing.Union[
214-
]: ...
215-
211+
) -> api_client.ApiResponseWithoutDeserialization: ...
216212
@typing.overload
217213
def delete_pet(
218214
self,
@@ -263,9 +259,7 @@ def delete(
263259
stream: bool = False,
264260
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
265261
skip_deserialization: typing_extensions.Literal[False] = False,
266-
) -> typing.Union[
267-
]: ...
268-
262+
) -> api_client.ApiResponseWithoutDeserialization: ...
269263
@typing.overload
270264
def delete(
271265
self,

samples/openapi3/client/petstore/python/petstore_api/paths/pet_pet_id/delete.pyi

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ class BaseApi(api_client.Api):
100100
stream: bool = False,
101101
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
102102
skip_deserialization: typing_extensions.Literal[False] = False,
103-
) -> typing.Union[
104-
]: ...
105-
103+
) -> api_client.ApiResponseWithoutDeserialization: ...
106104
@typing.overload
107105
def _delete_pet_oapg(
108106
self,
@@ -202,9 +200,7 @@ class DeletePet(BaseApi):
202200
stream: bool = False,
203201
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
204202
skip_deserialization: typing_extensions.Literal[False] = False,
205-
) -> typing.Union[
206-
]: ...
207-
203+
) -> api_client.ApiResponseWithoutDeserialization: ...
208204
@typing.overload
209205
def delete_pet(
210206
self,
@@ -255,9 +251,7 @@ class ApiFordelete(BaseApi):
255251
stream: bool = False,
256252
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
257253
skip_deserialization: typing_extensions.Literal[False] = False,
258-
) -> typing.Union[
259-
]: ...
260-
254+
) -> api_client.ApiResponseWithoutDeserialization: ...
261255
@typing.overload
262256
def delete(
263257
self,

samples/openapi3/client/petstore/python/petstore_api/paths/pet_pet_id/post.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ def _update_pet_with_form_oapg(
153153
stream: bool = False,
154154
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
155155
skip_deserialization: typing_extensions.Literal[False] = False,
156-
) -> typing.Union[
157-
]: ...
158-
156+
) -> api_client.ApiResponseWithoutDeserialization: ...
159157
@typing.overload
160158
def _update_pet_with_form_oapg(
161159
self,
@@ -261,9 +259,7 @@ def update_pet_with_form(
261259
stream: bool = False,
262260
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
263261
skip_deserialization: typing_extensions.Literal[False] = False,
264-
) -> typing.Union[
265-
]: ...
266-
262+
) -> api_client.ApiResponseWithoutDeserialization: ...
267263
@typing.overload
268264
def update_pet_with_form(
269265
self,
@@ -319,9 +315,7 @@ def post(
319315
stream: bool = False,
320316
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
321317
skip_deserialization: typing_extensions.Literal[False] = False,
322-
) -> typing.Union[
323-
]: ...
324-
318+
) -> api_client.ApiResponseWithoutDeserialization: ...
325319
@typing.overload
326320
def post(
327321
self,

samples/openapi3/client/petstore/python/petstore_api/paths/pet_pet_id/post.pyi

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ class BaseApi(api_client.Api):
145145
stream: bool = False,
146146
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
147147
skip_deserialization: typing_extensions.Literal[False] = False,
148-
) -> typing.Union[
149-
]: ...
150-
148+
) -> api_client.ApiResponseWithoutDeserialization: ...
151149
@typing.overload
152150
def _update_pet_with_form_oapg(
153151
self,
@@ -253,9 +251,7 @@ class UpdatePetWithForm(BaseApi):
253251
stream: bool = False,
254252
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
255253
skip_deserialization: typing_extensions.Literal[False] = False,
256-
) -> typing.Union[
257-
]: ...
258-
254+
) -> api_client.ApiResponseWithoutDeserialization: ...
259255
@typing.overload
260256
def update_pet_with_form(
261257
self,
@@ -311,9 +307,7 @@ class ApiForpost(BaseApi):
311307
stream: bool = False,
312308
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
313309
skip_deserialization: typing_extensions.Literal[False] = False,
314-
) -> typing.Union[
315-
]: ...
316-
310+
) -> api_client.ApiResponseWithoutDeserialization: ...
317311
@typing.overload
318312
def post(
319313
self,

samples/openapi3/client/petstore/python/petstore_api/paths/store_order_order_id/delete.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ def _delete_order_oapg(
9191
stream: bool = False,
9292
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
9393
skip_deserialization: typing_extensions.Literal[False] = False,
94-
) -> typing.Union[
95-
]: ...
96-
94+
) -> api_client.ApiResponseWithoutDeserialization: ...
9795
@typing.overload
9896
def _delete_order_oapg(
9997
self,
@@ -176,9 +174,7 @@ def delete_order(
176174
stream: bool = False,
177175
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
178176
skip_deserialization: typing_extensions.Literal[False] = False,
179-
) -> typing.Union[
180-
]: ...
181-
177+
) -> api_client.ApiResponseWithoutDeserialization: ...
182178
@typing.overload
183179
def delete_order(
184180
self,
@@ -224,9 +220,7 @@ def delete(
224220
stream: bool = False,
225221
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
226222
skip_deserialization: typing_extensions.Literal[False] = False,
227-
) -> typing.Union[
228-
]: ...
229-
223+
) -> api_client.ApiResponseWithoutDeserialization: ...
230224
@typing.overload
231225
def delete(
232226
self,

0 commit comments

Comments
 (0)