feat(dotnet-sdk): Added support for an interface on the client
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.
[!IMPORTANT]
Review skipped
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein 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
OpenFgaClientimplements all interface members fromIOpenFgaClientwithout breaking existing behavior. -
Validation logic: Review the new null-check in
ReadAuthorizationModelfor 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
@CharlieDigital Thanks for the PR. We will assign someone to review it.
@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 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
Hey there; checking in to see if there's anything missing on this PR or anything that requires additional attention.