Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot customize httpClient timeouts using the ClientOptions builder in the generated Java SDK #6456

Open
a-ignatov-parc opened this issue Mar 14, 2025 · 0 comments

Comments

@a-ignatov-parc
Copy link

Which Fern component?

SDK Generator

How urgent is this?

P1 - High (Strongly needed)

What's the issue?

Steps to reproduce:

  1. Generate any API spec

Actual result

The generated Builder class in ClientOptions.java has an issue with premature instantiation of the httpClient. The default timeout is set during initialization, which prevents adjusting the timeout through the builder method.

Here's an example of current generation

public final class ClientOptions {
    public static final class Builder {
        private OkHttpClient httpClient = new OkHttpClient.Builder()
                .addInterceptor(new RetryInterceptor(3))
                .callTimeout(this.timeout, TimeUnit.SECONDS)
                .build();

        public Builder timeout(int timeout) {
            this.timeout = timeout;
            return this;
        }

        public ClientOptions build() {
            return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout);
        }
    }
}

Expected result

The Builder class should be generated in a way that either reinitializes or lazily builds the httpClient in the build method to allow timeout adjustment.

Additional information

How ClientOptions was generated previously in fernapi/[email protected]

public final class ClientOptions {
    public static final class Builder {
        public Builder timeout(int timeout) {
            this.timeout = timeout;
            return this;
        }

        public ClientOptions build() {
            OkHttpClient okhttpClient = new OkHttpClient.Builder()
                    .addInterceptor(new RetryInterceptor(3))
                    .callTimeout(this.timeout, TimeUnit.SECONDS)
                    .build();
            return new ClientOptions(environment, headers, headerSuppliers, okhttpClient, this.timeout);
        }
    }
}

Fern CLI & Generator Versions

  • Fern CLI version: 0.56.12
  • SDK Generator versions:
    • fernapi/fern-java-sdk: 2.21.0

Workaround

The only way to adjust the timeout is to provide a custom httpClient to a Builder instance with the desired settings.

Logs & Additional Context

No response

Are you interested in contributing a fix?

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant