You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache
+38-9Lines changed: 38 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,8 @@
1
+
{{! Openapi Generator }}
2
+
{{! Copyright (2024) András Gábor Kis, Deutsche Telekom AG }}
3
+
{{! This file is made available under the terms of the license Apache-2.0 license }}
4
+
{{! SPDX-License-Identifier: Apache-2.0 }}
5
+
1
6
{{>licenseInfo}}
2
7
package {{package}};
3
8
@@ -271,16 +276,40 @@ public class {{classname}} {
271
276
}
272
277
{{/vendorExtensions.x-java-text-plain-string}}
273
278
{{^vendorExtensions.x-java-text-plain-string}}
274
-
return new ApiResponse<{{{returnType}}}{{^returnType}}Void{{/returnType}}>(
275
-
localVarResponse.statusCode(),
276
-
localVarResponse.headers().map(),
277
-
{{#returnType}}
278
-
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<{{{returnType}}}>() {}) // closes the InputStream
279
-
{{/returnType}}
280
-
{{^returnType}}
281
-
null
282
-
{{/returnType}}
279
+
{{#returnType}}
280
+
{{! Fix for https://github.com/OpenAPITools/openapi-generator/issues/13968 }}
281
+
{{! This part had a bugfix for an empty response in the past, but this part of that PR was reverted because it was not doing anything. }}
282
+
{{! Keep this documentation here, because the problem is not obvious. }}
283
+
{{! `InputStream.available()` was used, but that only works for inputstreams that are already in memory, it will not give the right result if it is a remote stream. We only work with remote streams here. }}
{{! The `available` method would work with a `PushbackInputStream`, because we could read 1 byte to check if it exists then push it back so Jackson can read it again. The issue with that is that it will also insert an ascii character for "head of input"and that will break Jackson as it does not handle special whitespace characters. }}
286
+
{{! A fix for that problem is to read it into a string and remove those characters, but if we need to read it before giving it to jackson to fix the string then just reading it into a string as is to do an emptiness check is the cleaner solution. }}
287
+
{{! We could also manipulate the inputstream to remove that bad character, but string manipulation is easier to read and this codepath is not asyncronus so we do not gain anything by reading the stream later. }}
288
+
{{! This fix does make it unsuitable for large amounts of data because `InputStream.readAllbytes` is not meant for it, but a syncronus client is already not the right tool for that.}}
289
+
if (localVarResponse.body() == null) {
290
+
return new ApiResponse<{{{returnType}}}>(
291
+
localVarResponse.statusCode(),
292
+
localVarResponse.headers().map(),
293
+
null
294
+
);
295
+
}
296
+
297
+
String responseBody = new String(localVarResponse.body().readAllBytes());
298
+
localVarResponse.body().close();
299
+
300
+
return new ApiResponse<{{{returnType}}}>(
301
+
localVarResponse.statusCode(),
302
+
localVarResponse.headers().map(),
303
+
responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<{{{returnType}}}>() {})
0 commit comments