Skip to content

fix(java-sdk): fix passing model ID in BatchCheck - #555

Merged
rhamzeh merged 3 commits into
mainfrom
codex/implement-issue-551-from-sdk-generator
Jun 16, 2025
Merged

fix(java-sdk): fix passing model ID in BatchCheck#555
rhamzeh merged 3 commits into
mainfrom
codex/implement-issue-551-from-sdk-generator

Conversation

@aaguiarz

@aaguiarz aaguiarz commented Jun 9, 2025

Copy link
Copy Markdown
Member

Summary

  • add Authorization Model ID telemetry for Java batchCheck
  • include options' authorizationModelId in batchCheck requests
  • test passing authorizationModelId via batchCheck options

Testing

  • make test-client-java (fails: docker not found)

https://chatgpt.com/codex/tasks/task_e_6846b74224688322925a10d153f3fca5

Summary by CodeRabbit

  • New Features

    • Enhanced telemetry to include the authorization model ID for batch check requests.
    • Improved batch check functionality to allow specifying the authorization model ID and consistency options.
  • Tests

    • Added a new test for batch check requests with authorization model ID and consistency options to ensure correct handling and response.

Closes openfga/java-sdk#177

@aaguiarz
aaguiarz requested a review from a team as a code owner June 9, 2025 10:53
jimmyjames
jimmyjames previously approved these changes Jun 9, 2025

@jimmyjames jimmyjames 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.

🏆

@rhamzeh rhamzeh changed the title Fix Java batchCheck authorization model id fix(java-sdk): fix passing model ID in BatchCheck Jun 16, 2025
rhamzeh
rhamzeh previously approved these changes Jun 16, 2025
@coderabbitai

coderabbitai Bot commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes update the Java SDK template to ensure the authorizationModelId is included in BatchCheckRequest payloads and telemetry attributes. The client logic now sets this field based on options or configuration, and a test verifies the correct request construction and behavior when authorizationModelId is specified.

Changes

File(s) Change Summary
config/clients/java/template/libraries/native/api.mustache Adds logic to include authorizationModelId in telemetry attributes for BatchCheckRequest.
config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache Updates batchCheck method to set authorizationModelId in request, using options or default configuration.
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache Adds a test verifying batchCheck with options, including authorizationModelId in the request.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant OpenFgaClient
    participant API

    Client->>OpenFgaClient: batchCheck(items, options)
    OpenFgaClient->>OpenFgaClient: Build BatchCheckRequest
    Note right of OpenFgaClient: Set checks, consistency, authorizationModelId
    OpenFgaClient->>API: batchCheck(BatchCheckRequest)
    API-->>OpenFgaClient: BatchCheckResponse
    OpenFgaClient-->>Client: ClientBatchCheckResponse
Loading

Possibly related issues

Poem

In Java's code, a field was missed,
Now authorizationModelId can’t be dismissed!
With tests in place, and logic neat,
Batch checks now are quite complete.
The bunny hops, with code so bright—
All requests now send the field just right!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a066d00 and 83b20b9.

📒 Files selected for processing (1)
  • config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: build-and-test-python-sdk
  • GitHub Check: build-and-test-java-sdk
  • GitHub Check: build-and-test-dotnet-sdk
  • GitHub Check: build-and-test-go-sdk
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (actions)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (3)
config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (2)

2032-2039: Loosen JSON-body coupling – prefer semantic matchers over raw String.format.

The test hard-codes the exact JSON produced by the SDK (including field order and explicit null values).
Any innocuous re-ordering of fields or a serialization setting that omits nulls will make this test fail even though the client behaviour is still correct.

Consider switching to a body matcher that asserts only the relevant semantics, e.g.:

mockHttpClient.onPost(postUrl)
    .withBody(allOf(
        matchingJsonPath("$.checks[0].tuple_key.user", equalTo(DEFAULT_USER)),
        matchingJsonPath("$.authorization_model_id", equalTo(DEFAULT_AUTH_MODEL_ID)),
        matchingJsonPath("$.consistency", equalTo(ConsistencyPreference.MINIMIZE_LATENCY.name()))
    ))
    .doReturn(200, "{\"result\":{}}");

This keeps the test resilient to unrelated JSON formatting changes.


2052-2058: Minor assertion gap – verify HTTP-layer interaction count.

After invoking fga.batchCheck, you assert the request body and the emptiness of the result map, but you do not assert the call count on mockHttpClient. Adding:

mockHttpClient.verify().post(postUrl).called(1);

would mirror the pattern used in neighbouring tests and guard against accidental retries.

config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache (1)

698-702: Minor naming nit – avoid parameter shadowing for clarity.

Using request both as the lambda parameter and in outer scopes is slightly confusing. Renaming improves readability and prevents accidental misuse.

-Consumer<List<BatchCheckItem>> singleBatchCheckRequest = request -> call(() -> {
-    BatchCheckRequest body = new BatchCheckRequest().checks(request);
+Consumer<List<BatchCheckItem>> singleBatchCheckRequest = batchItems -> call(() -> {
+    BatchCheckRequest body = new BatchCheckRequest().checks(batchItems);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f5dd0b8 and a066d00.

📒 Files selected for processing (3)
  • config/clients/java/template/libraries/native/api.mustache (1 hunks)
  • config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache (1 hunks)
  • config/clients/java/template/src/test/api/client/OpenFgaClientTest.java.mustache (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Analyze (go)
  • GitHub Check: build-and-test-java-sdk
  • GitHub Check: build-and-test-go-sdk
  • GitHub Check: build-and-test-dotnet-sdk
  • GitHub Check: build-and-test-python-sdk
  • GitHub Check: build-and-test-js-sdk
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (1)
config/clients/java/template/libraries/native/api.mustache (1)

268-272: ```shell
#!/bin/bash
set -e

Search for any earlier occurrences of putting the model ID into telemetryAttributes

rg -n "FGA_CLIENT_REQUEST_MODEL_ID" config/clients/java/template/libraries/native/api.mustache

Locate the buildTelemetryAttributes method definition to see initial population logic

rg -n "buildTelemetryAttributes" -n 20 config/clients/java/template/libraries/native/api.mustache


</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment thread config/clients/java/template/src/main/api/client/OpenFgaClient.java.mustache Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@rhamzeh
rhamzeh dismissed stale reviews from jimmyjames and themself via 83b20b9 June 16, 2025 17:56
@rhamzeh
rhamzeh added this pull request to the merge queue Jun 16, 2025
Merged via the queue into main with commit ebbc40f Jun 16, 2025
@rhamzeh
rhamzeh deleted the codex/implement-issue-551-from-sdk-generator branch June 16, 2025 18:42
rhamzeh pushed a commit to openfga/java-sdk that referenced this pull request Jul 1, 2025
github-merge-queue Bot pushed a commit to openfga/java-sdk that referenced this pull request Jul 1, 2025
* fix(client): fix passing model ID in BatchCheck

bringing the openfga/sdk-generator#555 from the generator

* chore(docs): fix typo in README

source: openfga/sdk-generator#561

* chore: remove unnecessary if condition

source: openfga/sdk-generator#546

---------

Co-authored-by: Andrés Aguiar <andres.aguiar@gmail.com>
Co-authored-by: AlessandroMinoccheri <aminoccheri@inpost.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BatchCheck does not honor the passed in model ID

3 participants