feat(java): invocation-only dynamic snippets + clientImport - #17451
Open
cadesark wants to merge 2 commits into
Open
feat(java): invocation-only dynamic snippets + clientImport#17451cadesark wants to merge 2 commits into
cadesark wants to merge 2 commits into
Conversation
Mirrors the finalized TypeScript structured contract (PR #17393) and the Python (#17402) / Go (#17403) ports: alongside the full snippet, the generator now returns InvocationSnippetResponse = { snippet, imports, clientName, errors } for callers (e.g. docs code templates) that render the invocation inside code they already own. - snippet: the bare call (honoring options.clientVariableName), no client construction, no package/class/method scaffold, no trailing `;`. - imports: the Java `import ...;` block the call references, captured separately via a new java.renderNodeWithoutImports helper + JavaFile.getRenderedImports() (the Java analogue of the TS AST's toStringWithoutImports). Empty string when the call needs no imports; populated when the invocation constructs imported types inline (e.g. UUID.fromString / OffsetDateTime.parse / Optional.of). - clientName: the generated client class name (getRootClientClassNameForSnippets). - errors: preserved from the existing error reporter. Co-Authored-By: Claude <noreply@anthropic.com>
Populate the optional clientImport field on InvocationSnippetResponse for Java, mirroring TypeScript. Renders a bare reference to the generated root client class via renderNodeWithoutImports (at the snippet package, so the client's own package is not elided) and surfaces the resulting `import ...;` line separately from `imports` (which only carries imports the bare call references). Lets docs render the client construction without hand-authoring the import; empty string when the client needs none. Co-Authored-By: Claude <noreply@anthropic.com>
cadesark
force-pushed
the
cade/java-clientimport
branch
from
August 17, 2026 21:23
552c348 to
dbe498c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Populates the optional
clientImportfield onInvocationSnippetResponsefor the Java dynamic-snippets invocation generator, mirroring the TypeScript implementation on the base branch.generateInvocationSnippetSyncnow renders a bare reference to the generated root client class (getRootClientClassReference) via the existingjava.renderNodeWithoutImportshelper — rendered at the snippet package so the client's own package is not elided — and returns the resultingimport ...;line asclientImport. This is distinct fromimports, which only carries imports the bare call itself references. It lets docs render the client construction (new AcmeAcmeClient(...)) without hand-authoring the import. Empty string when the client needs no import.The exact line(s) added:
This PR also carries the cherry-picked Java invocation-only snippet commit (base for this work).
Testing
pnpm turbo run compile --filter @fern-api/java-dynamic-snippets— passesvitest run src/__test__/InvocationSnippet.test.ts— 6/6 pass, including a newclientImportassertionGenerated with Claude Code