[BUG] [JAVA] `HttpClient memberVarHttpClient` not `close`d
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I noticed that the XxxApi.java file generated when using library=native calls apiClient.getHttpClient() and stores the resulting HttpClient in a private field, but never calls .close() on it. (This class was made AutoCloseable in Java 21, and closing it is important to release resources.) Clients of the library could not easily work around this; they would have to pass in a special HttpClient.Builder which tracked all the times .build() was called, and retain weak references so they could be closed later.
openapi-generator version
openapi-generator-maven-plugin version 7.25.0
OpenAPI declaration file content or url
(see steps to reproduce)
Generation Details
(see steps to reproduce)
Steps to reproduce
git clone https://github.com/jenkinsci/cursor-origin-branch-source-plugin .
git checkout 2b2e1c5beaac428488aa5406e0d38721a572d57b
mvn -Pquick-build package
fgrep memberVarHttpClient target/generated-sources/openapi/io/jenkins/plugins/cursor_origin_branch_source/origin_openapi/api/OriginServiceApi.javaExpected: some call to memberVarHttpClient.close(). Actual: none, just created and then used to make requests.
NOTE: I tried to reproduce in trunk (f99cf3bbbbb9c5eee56f4298a667db0c326d40ee) but compilation failed for some apparently unrelated reason: missing Enum.java. (Bisected this to https://github.com/OpenAPITools/openapi-generator/pull/24812.) OriginServiceApi.java was still generated the same way, still compilable, still missing .close().
Related issues/PRs
(none found)
Suggest a fix
Whatever template change would effect
116,116c116,116
< public class OriginServiceApi {
---
> public class OriginServiceApi implements AutoCloseable {
158a159,162
> @Override
> public void close() {
> memberVarHttpClient.close();
> }when configured for Java 21+.
Source: OpenAPITools/openapi-generator