dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

feat(dotnet-sdk): Added support for an interface on the client

Open CharlieDigital opened this issue 3 months ago • 2 comments

Provides an interface for the OpenFgaClient to improve testability in DI scenarios by allowing mocks and substitutes to be created.

Description

What problem is being solved?

It is currently not possible to mock the OpenFgaClient in unit tests in .NET as its methods are not virtual and it does not provide an interface for mocking

How is it being solved?

This PR adds an interface extracted from the OpenFgaClient

What changes are made to solve it?

  • Added an interface for the OpenFgaClient
  • Reformatted comments to be idiomatic C# comment style for editor support
  • Changed implementation comments to <inheritdoc />

References

Review Checklist

  • [x] I have clicked on "allow edits by maintainers".
  • [x] 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]
  • [x] The correct base branch is being used, if not main
  • [x] I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Bug Fixes
    • Added validation to prevent null authorization model identifiers during read operations, improving error handling.

CharlieDigital avatar Nov 08 '25 20:11 CharlieDigital

[!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

Extracts the public API surface of OpenFgaClient into a new IOpenFgaClient interface, with OpenFgaClient now implementing both IDisposable and IOpenFgaClient. Added runtime validation in ReadAuthorizationModel to throw when AuthorizationModelId is null. Doc comments replaced with /// <inheritdoc /> directives.

Changes

Cohort / File(s) Summary
Interface Definition
src/OpenFga.Sdk/Client/IOpenFgaClient.cs
New public interface defining 20+ async methods for store management, authorization model handling, relationship operations, and assertion management. Methods accept request bodies/options and cancellation tokens, returning task-based responses.
Class Implementation
src/OpenFga.Sdk/Client/Client.cs
OpenFgaClient class signature updated to implement IOpenFgaClient in addition to IDisposable. Added null validation in ReadAuthorizationModel to throw if AuthorizationModelId is null. Doc comments replaced with /// <inheritdoc /> across multiple methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Interface method signatures: Verify all 20+ method signatures are correctly defined with proper parameter types, return types, and async patterns.
  • Implementation completeness: Confirm OpenFgaClient implements all interface members from IOpenFgaClient without breaking existing behavior.
  • Validation logic: Review the new null-check in ReadAuthorizationModel for correctness and ensure it aligns with intended runtime behavior.
  • Doc comment migration: Verify /// <inheritdoc /> replacements preserve semantic documentation across methods.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding an interface (IOpenFgaClient) to the OpenFgaClient class to enable mocking/substitution in dependency injection and testing scenarios.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

coderabbitai[bot] avatar Nov 08 '25 20:11 coderabbitai[bot]

@CharlieDigital Thanks for the PR. We will assign someone to review it.

dyeam0 avatar Nov 10 '25 03:11 dyeam0

@CharlieDigital I'd just like to confirm that your PR's intent is to only implement for .NET SDK (as compared to the first PR https://github.com/openfga/sdk-generator/pull/652 which attempted in the SDK generator for all languages)?

dyeam0 avatar Nov 13 '25 03:11 dyeam0

@dyeam0 That is correct; I am only aiming to update the .NET implementation.

Additional context: https://cloud-native.slack.com/archives/C06G1NNH47N/p1761829148780869?thread_ts=1761407689.874249&cid=C06G1NNH47N

image

CharlieDigital avatar Nov 13 '25 11:11 CharlieDigital

Hey there; checking in to see if there's anything missing on this PR or anything that requires additional attention.

CharlieDigital avatar Nov 17 '25 16:11 CharlieDigital