Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import java.util.concurrent.CompletableFuture;
{{>generatedAnnotation}}

{{#operations}}
public class {{classname}} {
public class {{classname}} implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -955,5 +955,20 @@ public class {{classname}} {
{{/hasParams}}
{{/vendorExtensions.x-group-parameters}}
{{/operation}}
/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: When a specification has a parameterless operationId close, this template emits both the endpoint method and this lifecycle method with the same Java signature, so generation produces uncompilable code. Reserve or rename colliding operation IDs before rendering the API methods.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache, line 968:

<comment>When a specification has a parameterless operationId `close`, this template emits both the endpoint method and this lifecycle method with the same Java signature, so generation produces uncompilable code. Reserve or rename colliding operation IDs before rendering the API methods.</comment>

<file context>
@@ -955,5 +955,20 @@ public class {{classname}} {
+   * on earlier runtimes there is no way to release the client's threads early.
+   */
+  @Override
+  public void close() throws Exception {
+    if (memberVarHttpClient instanceof AutoCloseable) {
+      ((AutoCloseable) memberVarHttpClient).close();
</file context>

if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
Comment on lines +968 to +972

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Generated APIs force try-with-resources callers to handle checked Exception, although Java 21 HttpClient.close() has no checked exception. Remove throws Exception and translate the reflective/interface close failure to an unchecked exception.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/native/api.mustache, line 968:

<comment>Generated APIs force try-with-resources callers to handle checked `Exception`, although Java 21 `HttpClient.close()` has no checked exception. Remove `throws Exception` and translate the reflective/interface close failure to an unchecked exception.</comment>

<file context>
@@ -955,5 +955,20 @@ public class {{classname}} {
+   * on earlier runtimes there is no way to release the client's threads early.
+   */
+  @Override
+  public void close() throws Exception {
+    if (memberVarHttpClient instanceof AutoCloseable) {
+      ((AutoCloseable) memberVarHttpClient).close();
</file context>
Suggested change
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
public void close() {
if (memberVarHttpClient instanceof AutoCloseable) {
try {
((AutoCloseable) memberVarHttpClient).close();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class AuthApi {
public class AuthApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -367,4 +367,19 @@ private HttpRequest.Builder testAuthHttpBearerRequestBuilder(Map<String, String>
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The new close()-based resource lifecycle has no test coverage in this sample: AuthApiTest.java never calls close() or exercises the AutoCloseable path. Since this sample compiles with maven.compiler.source/target = 11, the instanceof AutoCloseable guard is always false on the baseline JVM, so the added behavior is silently a no-op in every test/CI run and would only be exercised on a Java 21+ runtime. Add a test (e.g., in AuthApiTest) that constructs an API instance, calls close(), and verifies it doesn't throw, at minimum catching regressions in the close() code path on any runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/java/native/src/main/java/org/openapitools/client/api/AuthApi.java, line 380:

<comment>The new close()-based resource lifecycle has no test coverage in this sample: AuthApiTest.java never calls close() or exercises the AutoCloseable path. Since this sample compiles with maven.compiler.source/target = 11, the `instanceof AutoCloseable` guard is always false on the baseline JVM, so the added behavior is silently a no-op in every test/CI run and would only be exercised on a Java 21+ runtime. Add a test (e.g., in AuthApiTest) that constructs an API instance, calls close(), and verifies it doesn't throw, at minimum catching regressions in the close() code path on any runtime.</comment>

<file context>
@@ -367,4 +367,19 @@ private HttpRequest.Builder testAuthHttpBearerRequestBuilder(Map<String, String>
+   * on earlier runtimes there is no way to release the client's threads early.
+   */
+  @Override
+  public void close() throws Exception {
+    if (memberVarHttpClient instanceof AutoCloseable) {
+      ((AutoCloseable) memberVarHttpClient).close();
</file context>

if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class BodyApi {
public class BodyApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -1376,4 +1376,19 @@ private HttpRequest.Builder testEchoBodyTagResponseStringRequestBuilder(@javax.a
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class FormApi {
public class FormApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -607,4 +607,19 @@ private HttpRequest.Builder testFormOneofRequestBuilder(@javax.annotation.Nullab
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class HeaderApi {
public class HeaderApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -306,4 +306,19 @@ private HttpRequest.Builder testHeaderIntegerBooleanStringEnumsRequestBuilder(@j
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class PathApi {
public class PathApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -307,4 +307,19 @@ private HttpRequest.Builder testsPathStringPathStringIntegerPathIntegerEnumNonre
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class QueryApi {
public class QueryApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -1567,4 +1567,19 @@ private HttpRequest.Builder testQueryStyleJsonSerializationObjectRequestBuilder(
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class AnotherFakeApi {
public class AnotherFakeApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -297,4 +297,19 @@ private HttpRequest.Builder call123testSpecialTagsRequestBuilder(@javax.annotati
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class DefaultApi {
public class DefaultApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -283,4 +283,19 @@ private HttpRequest.Builder fooGetRequestBuilder(Map<String, String> headers) th
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class FakeApi {
public class FakeApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -3051,4 +3051,19 @@ private HttpRequest.Builder testStringMapReferenceRequestBuilder(@javax.annotati
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class FakeClassnameTags123Api {
public class FakeClassnameTags123Api implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -303,4 +303,19 @@ private HttpRequest.Builder testClassnameRequestBuilder(@javax.annotation.Nonnul
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class PetApi {
public class PetApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -1429,4 +1429,19 @@ private HttpRequest.Builder uploadFileWithRequiredFileRequestBuilder(@javax.anno
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import java.util.concurrent.CompletableFuture;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.26.0-SNAPSHOT")
public class StoreApi {
public class StoreApi implements AutoCloseable {
/**
* Utility class for extending HttpRequest.Builder functionality.
*/
Expand Down Expand Up @@ -660,4 +660,19 @@ private HttpRequest.Builder placeOrderRequestBuilder(@javax.annotation.Nonnull O
return localVarRequestBuilder;
}

/**
* Closes the {@link HttpClient} that this instance created from the {@link ApiClient}
* it was constructed with. {@code ApiClient.getHttpClient()} builds a new client on
* every call, so the client held here is owned exclusively by this instance and is not
* shared with any other API instance.
*
* <p>{@link HttpClient} only became {@link AutoCloseable} in Java 21, hence the guard;
* on earlier runtimes there is no way to release the client's threads early.
*/
@Override
public void close() throws Exception {
if (memberVarHttpClient instanceof AutoCloseable) {
((AutoCloseable) memberVarHttpClient).close();
}
}
}
Loading
Loading