Skip to content

Conversation

@SoulPancake
Copy link
Member

@SoulPancake SoulPancake commented Nov 26, 2025

Description

generates openfga/java-sdk#261

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Copilot AI review requested due to automatic review settings November 26, 2025 12:49
@SoulPancake SoulPancake requested a review from a team as a code owner November 26, 2025 12:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 26, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

This PR adds Java streaming API support by introducing template files for streaming response handling. Three new classes are defined: StreamResult<T> (generic wrapper), BaseStreamingApi (abstract base for streaming), and StreamedListObjectsApi (concrete implementation). Configuration overrides are added to map these templates to their target Java source locations.

Changes

Cohort / File(s) Summary
Configuration mapping
config/clients/java/config.overrides.json
Adds four new mustache-to-destination mappings for streaming API templates: StreamResult.mustache, BaseStreamingApi.mustache, and StreamedListObjectsApi.mustache, all categorized as SupportingFiles.
Streaming response wrapper
config/clients/java/template/libraries/native/StreamResult.mustache
Introduces generic StreamResult<T> class with fluent setters, Jackson annotations, and standard object overrides. Models line-by-line deserialized streaming responses containing either a result of type T or an error of type Status.
Base streaming handler
config/clients/java/template/libraries/native/BaseStreamingApi.mustache
Defines abstract BaseStreamingApi<T> class with centralized HTTP streaming logic via processStreamingResponse(), line-level parsing in processLine(), robust error handling with optional errorConsumer, and HTTP request construction via buildHttpRequest().
Streamed API endpoint
config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache
Introduces StreamedListObjectsApi extending BaseStreamingApi<StreamedListObjectsResponse> with four overloaded streamedListObjects() methods supporting optional configuration overrides and error callbacks. Validates required parameters and constructs streaming HTTP POST requests.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant StreamedListObjectsApi
    participant BaseStreamingApi
    participant HttpClient
    participant Consumer

    Client->>StreamedListObjectsApi: streamedListObjects(storeId, body, consumer)
    StreamedListObjectsApi->>StreamedListObjectsApi: validateParameters()
    StreamedListObjectsApi->>StreamedListObjectsApi: buildHttpRequest(POST, path, body)
    StreamedListObjectsApi->>BaseStreamingApi: processStreamingResponse(request, consumer, errorConsumer)
    BaseStreamingApi->>HttpClient: send(httpRequest)
    HttpClient-->>BaseStreamingApi: response stream
    loop For each line
        BaseStreamingApi->>BaseStreamingApi: processLine(line)
        BaseStreamingApi->>BaseStreamingApi: deserialize to StreamResult<T>
        alt Error in StreamResult
            BaseStreamingApi->>BaseStreamingApi: invoke errorConsumer(error)
        else Success
            BaseStreamingApi->>Consumer: accept(result)
        end
    end
    BaseStreamingApi-->>Client: CompletableFuture<Void>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • BaseStreamingApi: Extra attention needed for streaming logic correctness, error handling patterns (CompletionException unwrapping), and async consumer delivery semantics
  • StreamedListObjectsApi: Verify multiple method overloads are correct and parameter validation is comprehensive
  • Configuration mappings: Confirm template destination paths and file categorization are accurate

Possibly related PRs

Suggested reviewers

  • ewanharris
  • rhamzeh

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: introducing common streaming utilities and a reverse sync streaming API layer for the Java SDK, which matches the new BaseStreamingApi, StreamResult, and StreamedListObjectsApi classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
config/clients/java/template/libraries/native/BaseStreamingApi.mustache (1)

131-137: Redundant null check.

The result != null check on line 134 is unnecessary since streamResult.getResult() != null was already verified on line 131.

             } else if (streamResult.getResult() != null) {
                 // Deliver the response object to the consumer
-                T result = streamResult.getResult();
-                if (result != null) {
-                    consumer.accept(result);
-                }
+                consumer.accept(streamResult.getResult());
             }
config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache (2)

11-12: Unused imports.

Status and StreamResult are imported but not used in this class—they're only referenced in the parent BaseStreamingApi.

-import {{modelPackage}}.Status;
-import {{modelPackage}}.StreamResult;

133-134: Redundant .toString() on String parameter.

storeId is already a String, so .toString() is unnecessary.

         String path = "/stores/{store_id}/streamed-list-objects"
-                .replace("{store_id}", StringUtil.urlEncode(storeId.toString()));
+                .replace("{store_id}", StringUtil.urlEncode(storeId));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f95f898 and e75e8e9.

📒 Files selected for processing (4)
  • config/clients/java/config.overrides.json (1 hunks)
  • config/clients/java/template/libraries/native/BaseStreamingApi.mustache (1 hunks)
  • config/clients/java/template/libraries/native/StreamResult.mustache (1 hunks)
  • config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
config/**/*.mustache

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Validate mustache syntax and variable references across all template files, including CHANGELOG.md.mustache

Files:

  • config/clients/java/template/libraries/native/BaseStreamingApi.mustache
  • config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache
  • config/clients/java/template/libraries/native/StreamResult.mustache
config/**/*.{json,mustache}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Never hardcode API keys or credentials in configuration or template files

Files:

  • config/clients/java/template/libraries/native/BaseStreamingApi.mustache
  • config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache
  • config/clients/java/config.overrides.json
  • config/clients/java/template/libraries/native/StreamResult.mustache
config/clients/*/config.overrides.json

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

config/clients/*/config.overrides.json: Always update the packageVersion in each language-specific config.overrides.json when making version changes
Maintain FOSSA compliance notice IDs in each language’s config.overrides.json

Files:

  • config/clients/java/config.overrides.json
config/{common/config.base.json,clients/*/config.overrides.json}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Ensure consistent versioning across base and language override configuration files to avoid version conflicts

Files:

  • config/clients/java/config.overrides.json
🧠 Learnings (3)
📚 Learning: 2025-08-12T14:18:58.827Z
Learnt from: rhamzeh
Repo: openfga/sdk-generator PR: 573
File: config/clients/java/config.overrides.json:184-191
Timestamp: 2025-08-12T14:18:58.827Z
Learning: In the OpenFGA SDK generator, templates are inherited from the upstream OpenAPI Generator (openapitools/openapi-generator-cli). Only custom or modified templates need to be explicitly defined in the config overrides files. Base templates like `settings.gradle.mustache` are provided by the upstream generator and don't require override mappings.

Applied to files:

  • config/clients/java/config.overrides.json
📚 Learning: 2025-09-04T17:35:34.111Z
Learnt from: CR
Repo: openfga/sdk-generator PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-04T17:35:34.111Z
Learning: Applies to config/clients/*/config.overrides.json : Maintain FOSSA compliance notice IDs in each language’s config.overrides.json

Applied to files:

  • config/clients/java/config.overrides.json
📚 Learning: 2025-09-04T17:35:34.111Z
Learnt from: CR
Repo: openfga/sdk-generator PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-09-04T17:35:34.111Z
Learning: Applies to scripts/build_client.sh : Implement and maintain OpenAPI transformations in scripts/build_client.sh (remove streaming endpoints, rename Object to FgaObject, strip v1. prefixes) when API schemas change

Applied to files:

  • config/clients/java/config.overrides.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Agent
  • GitHub Check: build-and-test-dotnet-sdk
  • GitHub Check: build-and-test-go-sdk
  • GitHub Check: build-and-test-java-sdk
🔇 Additional comments (5)
config/clients/java/template/libraries/native/StreamResult.mustache (1)

1-111: LGTM! Well-structured streaming result wrapper.

The generic StreamResult<T> class is properly designed with:

  • Correct Jackson annotations for JSON serialization
  • Fluent setter pattern consistent with other SDK model classes
  • Proper equals, hashCode, and toString implementations

The generic type handling is correctly delegated to TypeReference in the consuming BaseStreamingApi class.

config/clients/java/template/libraries/native/BaseStreamingApi.mustache (1)

59-108: Solid async streaming implementation.

The processStreamingResponse method correctly:

  • Uses try-with-resources on Stream<String> for proper resource cleanup
  • Unwraps CompletionException to expose the actual cause
  • Notifies errorConsumer while also keeping the CompletableFuture in a failed state

This dual error-handling approach (callback + future state) gives callers flexibility.

config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache (1)

44-117: Clean API overload pattern.

The four public overloads provide good ergonomics for callers—allowing optional errorConsumer and configurationOverride without requiring null parameters. Delegation to the private helper method keeps the implementation DRY.

config/clients/java/config.overrides.json (2)

6-6: Consider version bump for new streaming API feature.

This PR introduces new streaming API classes. Depending on your release process, you may want to bump packageVersion (currently 0.9.2) to reflect the new functionality.

Based on coding guidelines, version updates should be considered when making feature changes.


40-52: Based on my verification, I can see that:

  1. ✅ All three template files exist at the correct paths
  2. ✅ Template mappings are properly configured with correct destination paths
  3. ⚠️ The packageVersion (0.9.2) was NOT updated, but this is a feature addition ("feat:" commit)

The original review comment's concern about version consistency is valid. Per the commit message "feat(java-sdk): use common streaming utils" and coding guidelines, a version bump should be considered.

Here's the rewritten review comment:


Update packageVersion for new streaming API support.

Template mappings for StreamResult, BaseStreamingApi, and StreamedListObjectsApi are correctly configured and files exist at the expected locations. However, per coding guidelines, the packageVersion in config/clients/java/config.overrides.json should be updated from 0.9.2 to reflect this feature addition (currently Python SDK is at 0.9.7, indicating independent versioning per language). Consider bumping to 0.9.3 for this minor feature.

"packageVersion": "0.9.3"
⛔ Skipped due to learnings
Learnt from: rhamzeh
Repo: openfga/sdk-generator PR: 573
File: config/clients/java/config.overrides.json:184-191
Timestamp: 2025-08-12T14:18:58.827Z
Learning: In the OpenFGA SDK generator, templates are inherited from the upstream OpenAPI Generator (openapitools/openapi-generator-cli). Only custom or modified templates need to be explicitly defined in the config overrides files. Base templates like `settings.gradle.mustache` are provided by the upstream generator and don't require override mappings.

Copilot finished reviewing on behalf of SoulPancake November 26, 2025 12:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds streaming API support to the Java SDK by introducing common streaming utilities and a new API layer for the streamedListObjects endpoint. The implementation follows the pattern established in the Go SDK, using a generic StreamResult wrapper and a base class for shared streaming functionality.

Key Changes

  • Introduced BaseStreamingApi abstract class providing reusable streaming logic with async CompletableFuture-based processing
  • Added StreamResult<T> generic model for deserializing streaming responses that contain either results or errors
  • Implemented StreamedListObjectsApi extending the base class for the streaming list objects endpoint

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
config/clients/java/template/libraries/native/BaseStreamingApi.mustache Base class providing common streaming functionality with HTTP client integration, line-by-line JSON parsing, and error handling
config/clients/java/template/libraries/native/StreamResult.mustache Generic wrapper model for streaming responses with result/error union type, following Go SDK pattern
config/clients/java/template/libraries/native/StreamedListObjectsApi.mustache API implementation for streaming list objects with multiple overloads supporting configuration and error handling
config/clients/java/config.overrides.json Configuration mappings for the three new template files to their destination paths in the generated SDK

@SoulPancake SoulPancake enabled auto-merge December 4, 2025 19:19
@SoulPancake SoulPancake added this pull request to the merge queue Dec 4, 2025
Merged via the queue into main with commit 717ed21 Dec 4, 2025
11 of 15 checks passed
@SoulPancake SoulPancake deleted the feat/java-sdk/use-common-streaming-utils branch December 4, 2025 19:20
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.

3 participants