Skip to content

chore(java): use IR discriminatorContext for SSE event-level discrimination#12495

Closed
tstanmay13 wants to merge 2 commits intomainfrom
devin/1771354685-java-sse-use-ir-discriminator-context
Closed

chore(java): use IR discriminatorContext for SSE event-level discrimination#12495
tstanmay13 wants to merge 2 commits intomainfrom
devin/1771354685-java-sse-use-ir-discriminator-context

Conversation

@tstanmay13
Copy link
Copy Markdown
Contributor

Description

Refs #12242

Refactors the Java SDK generator's SSE event-level discrimination logic to use the IR's discriminatorContext field (added in PR #12242) instead of the manual heuristic that checked if a discriminator property name matched SSE envelope fields (event, id, retry, data).

Link to Devin run: https://app.devin.ai/sessions/76958a26d45348e6ab03ffbbc7647ad2
Requested by: @tstanmay13

Changes Made

  • AbstractGeneratorCli: Extracts discriminatorContext from raw IR JSON before Jackson deserialization (the irV63 Java model doesn't expose this field, but it's present in the JSON). New IrLoadResult wrapper, loadIr() replaces getIr(), and extractDiscriminatorContexts() walks the JSON tree for union types.
  • AbstractGeneratorContext / ClientGeneratorContext: New constructor overload and getter to thread Map<TypeId, String> discriminatorContexts through the context hierarchy.
  • Cli: All 3 ClientGeneratorContext construction sites pass getDiscriminatorContexts().
  • SseDiscriminationAnalyzer: Core change — replaces SSE_ENVELOPE_FIELDS.contains(...) with a lookup into the discriminator contexts map. "protocol" → event-level, "data" or absent → data-level. resolveUnionType now returns UnionResolutionResult (TypeId + union) instead of just the union declaration.
  • AbstractHttpResponseParserGenerator: Updated caller to pass discriminator contexts.
  • versions.yml: New 3.36.2 entry.

Testing

  • Java compilation passes (./gradlew compileJava)
  • Spotless formatting passes (./gradlew spotlessCheck)
  • No new unit tests added — relies on existing seed test coverage

Human Review Checklist

  • Raw JSON extraction approach: extractDiscriminatorContexts manually walks the IR JSON tree. This is necessary because the Java IR model (v63) doesn't expose discriminatorContext. Verify the JSON path (types -> {id} -> shape -> discriminatorContext) matches the actual IR structure.
  • Default fallback behavior change: Previously any discriminator named event/id/retry/data was treated as event-level. Now only types explicitly marked discriminatorContext: "protocol" in the IR get event-level treatment. If discriminatorContext is absent, it defaults to "data". Confirm this is the intended semantic for older IRs that predate the field.
  • Runtime SseEventParser.java unchanged: The resource template still has its own SSE_ENVELOPE_FIELDS for runtime parsing — this is intentional (separate concern from build-time analysis).
  • No test coverage: The new extraction logic and refactored analyzer have no unit tests. Seed tests should catch regressions, but manual verification may be needed.

…nation

Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 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 and CI monitoring

Co-Authored-By: tanmay.singh@buildwithfern.com <tstanmay13@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 25 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the Stale This PR hasn't has any commits or comments in 25 days or more. label Mar 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed because it has been inactive for 5 days after being marked stale.

@github-actions github-actions Bot closed this Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale This PR hasn't has any commits or comments in 25 days or more.

Development

Successfully merging this pull request may close these issues.

1 participant