Skip to content

docs: document custom-interceptors config for the Java SDK generator - #6509

Merged
cadesark merged 6 commits into
mainfrom
devin/1785769977-java-custom-interceptors-docs
Aug 3, 2026
Merged

docs: document custom-interceptors config for the Java SDK generator#6509
cadesark merged 6 commits into
mainfrom
devin/1785769977-java-custom-interceptors-docs

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

custom-interceptors has shipped in the Java SDK generator since 3.41.0 (2026-03-03) but only ever appeared in the generator changelog, so a customer reading /learn/sdks/generators/java/configuration has no way to discover it. This adds the config option to the Java configuration reference and a usage section to the Java custom-code page.

Behavior documented here was verified empirically, not inferred from the changelog: two fern generate --local runs against fernapi/fern-java-sdk:4.16.0 on the same spec, differing only by config: custom-interceptors: true. With the flag, the generated builder gains

public YourApiClientBuilder addInterceptor(Interceptor interceptor)   // collects into List<Interceptor>
protected void setInterceptors(ClientOptions.Builder builder)          // applied to the OkHttpClient at build()

plus the matching ClientOptions.Builder.addInterceptor(...); the control run has none of them. setInterceptors is generated whenever the flag is on (it does not require enable-extensible-builders), which is why it's listed in the extensible-builder method reference table as conditional on custom-interceptors rather than on the builder flag.

Two review questions are answered from the generator source (ClientOptionsGenerator.java) and the java-sdk seed fixtures under seed/java-sdk/*/custom-interceptors/, each condensed to a clause on the page:

Ordering relative to RetryInterceptor. ClientOptions.Builder.build() registers interceptors in this order, and OkHttp invokes application interceptors in registration order:

httpClientBuilder
    .addInterceptor(new RetryInterceptor(...))            // only when no caller-supplied OkHttpClient
    .addInterceptor(new LoggingInterceptor(logger))
    .addInterceptor(new ResponseDecompressionInterceptor());
for (Interceptor interceptor : this.interceptors) {       // custom, last
    httpClientBuilder.addInterceptor(interceptor);
}

Custom interceptors sit innermost, so RetryInterceptor.retryChain()'s repeated chain.proceed(...) re-enters them on every attempt: a signing interceptor signs each attempt independently rather than replaying the first signature.

OAuth staged builders. 3.42.5 added interceptors/addInterceptor to the _Builder inner class and forwarding through token()/credentials(). The seed fixture confirms addInterceptor exists both on _Builder and on the auth-stage builders (_TokenAuth, _CredentialsAuth), so the existing builder().token(...).addInterceptor(...) example is already correct for OAuth APIs; the page notes registration works on either side of the auth call.

Link to Devin session: https://app.devin.ai/sessions/018daf6fd74d4413a3b89f4f5c706f96

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration
devin-ai-integration Bot requested a review from devalog as a code owner August 3, 2026 15:13
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

devalog and others added 2 commits August 3, 2026 11:29
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
custom-interceptors: true
```

Developers using your SDK register interceptors as they construct the client. Each call to `addInterceptor` adds to the set, and all of them are applied to the underlying `OkHttpClient` at build time:

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.

📝 [vale] reported by reviewdog 🐶
[Microsoft.Wordiness] Consider using 'all' instead of 'all of'.

devalog and others added 3 commits August 3, 2026 15:33
…pport

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cadesark
cadesark merged commit ac17555 into main Aug 3, 2026
4 checks passed
@cadesark
cadesark deleted the devin/1785769977-java-custom-interceptors-docs branch August 3, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants