Skip to content

Commit 440e3f3

Browse files
feliksikwing328
authored andcommitted
Re-interrupt the thread in the generated code (#4382)
* Re-interrupt the thread in the generated code, otherwise the client has to check for the type of the cause of the thrown exception. * update samples
1 parent 34c715e commit 440e3f3

7 files changed

Lines changed: 152 additions & 38 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ public class {{classname}} {
148148
{{#returnType}}
149149
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {});
150150
{{/returnType}}
151-
} catch (IOException | InterruptedException e) {
151+
} catch (IOException e) {
152+
throw new ApiException(e);
153+
} catch (InterruptedException e) {
154+
Thread.currentThread().interrupt();
152155
throw new ApiException(e);
153156
}
154157
}

samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/AnotherFakeApi.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public Client call123testSpecialTags(Client body) throws ApiException {
9898
}
9999

100100
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Client>() {});
101-
} catch (IOException | InterruptedException e) {
101+
} catch (IOException e) {
102+
throw new ApiException(e);
103+
} catch (InterruptedException e) {
104+
Thread.currentThread().interrupt();
102105
throw new ApiException(e);
103106
}
104107
}

samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeApi.java

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ public void createXmlItem(XmlItem xmlItem) throws ApiException {
104104
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
105105
}
106106

107-
} catch (IOException | InterruptedException e) {
107+
} catch (IOException e) {
108+
throw new ApiException(e);
109+
} catch (InterruptedException e) {
110+
Thread.currentThread().interrupt();
108111
throw new ApiException(e);
109112
}
110113
}
@@ -147,7 +150,10 @@ public Boolean fakeOuterBooleanSerialize(Boolean body) throws ApiException {
147150
}
148151

149152
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Boolean>() {});
150-
} catch (IOException | InterruptedException e) {
153+
} catch (IOException e) {
154+
throw new ApiException(e);
155+
} catch (InterruptedException e) {
156+
Thread.currentThread().interrupt();
151157
throw new ApiException(e);
152158
}
153159
}
@@ -190,7 +196,10 @@ public OuterComposite fakeOuterCompositeSerialize(OuterComposite body) throws Ap
190196
}
191197

192198
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<OuterComposite>() {});
193-
} catch (IOException | InterruptedException e) {
199+
} catch (IOException e) {
200+
throw new ApiException(e);
201+
} catch (InterruptedException e) {
202+
Thread.currentThread().interrupt();
194203
throw new ApiException(e);
195204
}
196205
}
@@ -233,7 +242,10 @@ public BigDecimal fakeOuterNumberSerialize(BigDecimal body) throws ApiException
233242
}
234243

235244
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<BigDecimal>() {});
236-
} catch (IOException | InterruptedException e) {
245+
} catch (IOException e) {
246+
throw new ApiException(e);
247+
} catch (InterruptedException e) {
248+
Thread.currentThread().interrupt();
237249
throw new ApiException(e);
238250
}
239251
}
@@ -276,7 +288,10 @@ public String fakeOuterStringSerialize(String body) throws ApiException {
276288
}
277289

278290
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<String>() {});
279-
} catch (IOException | InterruptedException e) {
291+
} catch (IOException e) {
292+
throw new ApiException(e);
293+
} catch (InterruptedException e) {
294+
Thread.currentThread().interrupt();
280295
throw new ApiException(e);
281296
}
282297
}
@@ -321,7 +336,10 @@ public void testBodyWithFileSchema(FileSchemaTestClass body) throws ApiException
321336
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
322337
}
323338

324-
} catch (IOException | InterruptedException e) {
339+
} catch (IOException e) {
340+
throw new ApiException(e);
341+
} catch (InterruptedException e) {
342+
Thread.currentThread().interrupt();
325343
throw new ApiException(e);
326344
}
327345
}
@@ -380,7 +398,10 @@ public void testBodyWithQueryParams(String query, User body) throws ApiException
380398
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
381399
}
382400

383-
} catch (IOException | InterruptedException e) {
401+
} catch (IOException e) {
402+
throw new ApiException(e);
403+
} catch (InterruptedException e) {
404+
Thread.currentThread().interrupt();
384405
throw new ApiException(e);
385406
}
386407
}
@@ -427,7 +448,10 @@ public Client testClientModel(Client body) throws ApiException {
427448
}
428449

429450
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Client>() {});
430-
} catch (IOException | InterruptedException e) {
451+
} catch (IOException e) {
452+
throw new ApiException(e);
453+
} catch (InterruptedException e) {
454+
Thread.currentThread().interrupt();
431455
throw new ApiException(e);
432456
}
433457
}
@@ -495,7 +519,10 @@ public void testEndpointParameters(BigDecimal number, Double _double, String pat
495519
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
496520
}
497521

498-
} catch (IOException | InterruptedException e) {
522+
} catch (IOException e) {
523+
throw new ApiException(e);
524+
} catch (InterruptedException e) {
525+
Thread.currentThread().interrupt();
499526
throw new ApiException(e);
500527
}
501528
}
@@ -559,7 +586,10 @@ public void testEnumParameters(List<String> enumHeaderStringArray, String enumHe
559586
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
560587
}
561588

562-
} catch (IOException | InterruptedException e) {
589+
} catch (IOException e) {
590+
throw new ApiException(e);
591+
} catch (InterruptedException e) {
592+
Thread.currentThread().interrupt();
563593
throw new ApiException(e);
564594
}
565595
}
@@ -633,7 +663,10 @@ public void testGroupParameters(Integer requiredStringGroup, Boolean requiredBoo
633663
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
634664
}
635665

636-
} catch (IOException | InterruptedException e) {
666+
} catch (IOException e) {
667+
throw new ApiException(e);
668+
} catch (InterruptedException e) {
669+
Thread.currentThread().interrupt();
637670
throw new ApiException(e);
638671
}
639672
}
@@ -678,7 +711,10 @@ public void testInlineAdditionalProperties(Map<String, String> param) throws Api
678711
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
679712
}
680713

681-
} catch (IOException | InterruptedException e) {
714+
} catch (IOException e) {
715+
throw new ApiException(e);
716+
} catch (InterruptedException e) {
717+
Thread.currentThread().interrupt();
682718
throw new ApiException(e);
683719
}
684720
}
@@ -726,7 +762,10 @@ public void testJsonFormData(String param, String param2) throws ApiException {
726762
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
727763
}
728764

729-
} catch (IOException | InterruptedException e) {
765+
} catch (IOException e) {
766+
throw new ApiException(e);
767+
} catch (InterruptedException e) {
768+
Thread.currentThread().interrupt();
730769
throw new ApiException(e);
731770
}
732771
}
@@ -802,7 +841,10 @@ public void testQueryParameterCollectionFormat(List<String> pipe, List<String> i
802841
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
803842
}
804843

805-
} catch (IOException | InterruptedException e) {
844+
} catch (IOException e) {
845+
throw new ApiException(e);
846+
} catch (InterruptedException e) {
847+
Thread.currentThread().interrupt();
806848
throw new ApiException(e);
807849
}
808850
}

samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/FakeClassnameTags123Api.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public Client testClassname(Client body) throws ApiException {
9898
}
9999

100100
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Client>() {});
101-
} catch (IOException | InterruptedException e) {
101+
} catch (IOException e) {
102+
throw new ApiException(e);
103+
} catch (InterruptedException e) {
104+
Thread.currentThread().interrupt();
102105
throw new ApiException(e);
103106
}
104107
}

samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/PetApi.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public void addPet(Pet body) throws ApiException {
9898
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
9999
}
100100

101-
} catch (IOException | InterruptedException e) {
101+
} catch (IOException e) {
102+
throw new ApiException(e);
103+
} catch (InterruptedException e) {
104+
Thread.currentThread().interrupt();
102105
throw new ApiException(e);
103106
}
104107
}
@@ -146,7 +149,10 @@ public void deletePet(Long petId, String apiKey) throws ApiException {
146149
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
147150
}
148151

149-
} catch (IOException | InterruptedException e) {
152+
} catch (IOException e) {
153+
throw new ApiException(e);
154+
} catch (InterruptedException e) {
155+
Thread.currentThread().interrupt();
150156
throw new ApiException(e);
151157
}
152158
}
@@ -200,7 +206,10 @@ public List<Pet> findPetsByStatus(List<String> status) throws ApiException {
200206
}
201207

202208
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<List<Pet>>() {});
203-
} catch (IOException | InterruptedException e) {
209+
} catch (IOException e) {
210+
throw new ApiException(e);
211+
} catch (InterruptedException e) {
212+
Thread.currentThread().interrupt();
204213
throw new ApiException(e);
205214
}
206215
}
@@ -256,7 +265,10 @@ public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
256265
}
257266

258267
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<List<Pet>>() {});
259-
} catch (IOException | InterruptedException e) {
268+
} catch (IOException e) {
269+
throw new ApiException(e);
270+
} catch (InterruptedException e) {
271+
Thread.currentThread().interrupt();
260272
throw new ApiException(e);
261273
}
262274
}
@@ -302,7 +314,10 @@ public Pet getPetById(Long petId) throws ApiException {
302314
}
303315

304316
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Pet>() {});
305-
} catch (IOException | InterruptedException e) {
317+
} catch (IOException e) {
318+
throw new ApiException(e);
319+
} catch (InterruptedException e) {
320+
Thread.currentThread().interrupt();
306321
throw new ApiException(e);
307322
}
308323
}
@@ -347,7 +362,10 @@ public void updatePet(Pet body) throws ApiException {
347362
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
348363
}
349364

350-
} catch (IOException | InterruptedException e) {
365+
} catch (IOException e) {
366+
throw new ApiException(e);
367+
} catch (InterruptedException e) {
368+
Thread.currentThread().interrupt();
351369
throw new ApiException(e);
352370
}
353371
}
@@ -393,7 +411,10 @@ public void updatePetWithForm(Long petId, String name, String status) throws Api
393411
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
394412
}
395413

396-
} catch (IOException | InterruptedException e) {
414+
} catch (IOException e) {
415+
throw new ApiException(e);
416+
} catch (InterruptedException e) {
417+
Thread.currentThread().interrupt();
397418
throw new ApiException(e);
398419
}
399420
}
@@ -441,7 +462,10 @@ public ModelApiResponse uploadFile(Long petId, String additionalMetadata, File f
441462
}
442463

443464
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<ModelApiResponse>() {});
444-
} catch (IOException | InterruptedException e) {
465+
} catch (IOException e) {
466+
throw new ApiException(e);
467+
} catch (InterruptedException e) {
468+
Thread.currentThread().interrupt();
445469
throw new ApiException(e);
446470
}
447471
}
@@ -493,7 +517,10 @@ public ModelApiResponse uploadFileWithRequiredFile(Long petId, File requiredFile
493517
}
494518

495519
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<ModelApiResponse>() {});
496-
} catch (IOException | InterruptedException e) {
520+
} catch (IOException e) {
521+
throw new ApiException(e);
522+
} catch (InterruptedException e) {
523+
Thread.currentThread().interrupt();
497524
throw new ApiException(e);
498525
}
499526
}

samples/client/petstore/java/native/src/main/java/org/openapitools/client/api/StoreApi.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public void deleteOrder(String orderId) throws ApiException {
9595
localVarResponse.body() == null ? null : new String(localVarResponse.body().readAllBytes()));
9696
}
9797

98-
} catch (IOException | InterruptedException e) {
98+
} catch (IOException e) {
99+
throw new ApiException(e);
100+
} catch (InterruptedException e) {
101+
Thread.currentThread().interrupt();
99102
throw new ApiException(e);
100103
}
101104
}
@@ -135,7 +138,10 @@ public Map<String, Integer> getInventory() throws ApiException {
135138
}
136139

137140
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Map<String, Integer>>() {});
138-
} catch (IOException | InterruptedException e) {
141+
} catch (IOException e) {
142+
throw new ApiException(e);
143+
} catch (InterruptedException e) {
144+
Thread.currentThread().interrupt();
139145
throw new ApiException(e);
140146
}
141147
}
@@ -181,7 +187,10 @@ public Order getOrderById(Long orderId) throws ApiException {
181187
}
182188

183189
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Order>() {});
184-
} catch (IOException | InterruptedException e) {
190+
} catch (IOException e) {
191+
throw new ApiException(e);
192+
} catch (InterruptedException e) {
193+
Thread.currentThread().interrupt();
185194
throw new ApiException(e);
186195
}
187196
}
@@ -228,7 +237,10 @@ public Order placeOrder(Order body) throws ApiException {
228237
}
229238

230239
return memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<Order>() {});
231-
} catch (IOException | InterruptedException e) {
240+
} catch (IOException e) {
241+
throw new ApiException(e);
242+
} catch (InterruptedException e) {
243+
Thread.currentThread().interrupt();
232244
throw new ApiException(e);
233245
}
234246
}

0 commit comments

Comments
 (0)