Skip to content

feat(java): invocation-only dynamic snippets + clientImport - #17451

Open
cadesark wants to merge 2 commits into
cade/clientimport-invocation-snippetfrom
cade/java-clientimport
Open

feat(java): invocation-only dynamic snippets + clientImport#17451
cadesark wants to merge 2 commits into
cade/clientimport-invocation-snippetfrom
cade/java-clientimport

Conversation

@cadesark

@cadesark cadesark commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Populates the optional clientImport field on InvocationSnippetResponse for the Java dynamic-snippets invocation generator, mirroring the TypeScript implementation on the base branch.

generateInvocationSnippetSync now renders a bare reference to the generated root client class (getRootClientClassReference) via the existing java.renderNodeWithoutImports helper — rendered at the snippet package so the client's own package is not elided — and returns the resulting import ...; line as clientImport. This is distinct from imports, 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:

const { imports: clientImport } = java.renderNodeWithoutImports({
    node: this.context.getRootClientClassReference(),
    packageName: config.fullStylePackageName ?? SNIPPET_PACKAGE_NAME,
    customConfig: this.context.customConfig,
    formatter: this.formatter
});
// returned as: clientImport

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 — passes
  • vitest run src/__test__/InvocationSnippet.test.ts — 6/6 pass, including a new clientImport assertion

Generated with Claude Code


Open in Devin Review

@cadesark cadesark self-assigned this Aug 17, 2026

@nitpickybot nitpickybot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the changes — everything looks good. No issues found.

@devin-ai-integration devin-ai-integration Bot left a comment

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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

cadesark and others added 2 commits August 17, 2026 17:23
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
cadesark force-pushed the cade/java-clientimport branch from 552c348 to dbe498c Compare August 17, 2026 21:23
@cadesark cadesark changed the title feat(java): expose clientImport in invocation snippets feat(java): invocation-only dynamic snippets + clientImport Aug 18, 2026
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.

1 participant