Skip to content

chore: sync back sdk generator changes#102

Merged
rhamzeh merged 11 commits intomainfrom
chore/sync-generator-changes
May 9, 2025
Merged

chore: sync back sdk generator changes#102
rhamzeh merged 11 commits intomainfrom
chore/sync-generator-changes

Conversation

@rhamzeh
Copy link
Member

@rhamzeh rhamzeh commented Mar 28, 2025

Description

This brings in several changes (and should not be squashed).

It will:

  • Bring in generator changes Generator PR: fix : change default retry policy sdk-generator#420
  • Limit default retries to 3
  • Update Docs
  • Update API definitions to support assertions context and contextual tuples
  • Support contextual tuples in Expand
  • Support for start time in read changes request
  • Fix ListRelations swallowing errors

Note: This brings in all the API changes up to the most recent, however the wrapper OpenFgaClient does not yet support server-side BatchCheck. That will be in a followup PR

References

Includes and replaces #92, Closes #92
Closes #101
Closes #95

Generated by openfga/sdk-generator#526 based on the latest API openfga/api@f970913

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

Generator PR: openfga/sdk-generator#420

@rhamzeh rhamzeh requested review from a team as code owners March 28, 2025 17:56
@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2025

Codecov Report

Attention: Patch coverage is 8.00000% with 437 lines in your changes missing coverage. Please review.

Project coverage is 31.70%. Comparing base (8199014) to head (0836b21).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/OpenFga.Sdk/Model/BatchCheckItem.cs 0.00% 76 Missing ⚠️
src/OpenFga.Sdk/Model/BatchCheckRequest.cs 0.00% 62 Missing ⚠️
src/OpenFga.Sdk/Model/CheckError.cs 0.00% 56 Missing ⚠️
src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs 0.00% 49 Missing ⚠️
src/OpenFga.Sdk/Model/ForbiddenResponse.cs 0.00% 49 Missing ⚠️
src/OpenFga.Sdk/Model/BatchCheckResponse.cs 0.00% 43 Missing ⚠️
...penFga.Sdk/Client/Model/ClientListStoresRequest.cs 4.16% 23 Missing ⚠️
src/OpenFga.Sdk/Api/OpenFgaApi.cs 25.92% 19 Missing and 1 partial ⚠️
...enFga.Sdk/Client/Model/ClientBatchCheckResponse.cs 35.71% 14 Missing and 4 partials ⚠️
src/OpenFga.Sdk/Model/Assertion.cs 22.72% 17 Missing ⚠️
... and 4 more

❌ Your project status has failed because the head coverage (31.70%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #102      +/-   ##
==========================================
- Coverage   33.00%   31.70%   -1.31%     
==========================================
  Files         128      135       +7     
  Lines        6387     6848     +461     
  Branches      840      900      +60     
==========================================
+ Hits         2108     2171      +63     
- Misses       4099     4489     +390     
- Partials      180      188       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if (this.Context != null) {
hashCode = (hashCode * 9923) + this.Context.GetHashCode();
}
if (this.AdditionalProperties != null) {

Check warning

Code scanning / CodeQL

Reference equality test on System.Object Warning

Reference equality for System.Object comparisons (
this
argument has type Object).

Copilot Autofix

AI 11 months ago

To fix the problem, we need to ensure that the comparison of this.Context and input.Context is performed using the Equals method instead of the == operator. This will ensure that the comparison checks for value equality rather than reference equality.

  • Replace the reference comparison this.Context == input.Context with a value comparison using the Equals method.
  • Ensure that the Equals method is called only when this.Context is not null to avoid potential NullReferenceException.
Suggested changeset 1
src/OpenFga.Sdk/Model/Assertion.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/Assertion.cs b/src/OpenFga.Sdk/Model/Assertion.cs
--- a/src/OpenFga.Sdk/Model/Assertion.cs
+++ b/src/OpenFga.Sdk/Model/Assertion.cs
@@ -142,5 +142,4 @@
                 (
-                    this.Context == input.Context ||
-                    (this.Context != null &&
-                    this.Context.Equals(input.Context))
+                    (this.Context != null && this.Context.Equals(input.Context)) ||
+                    (this.Context == null && input.Context == null)
                 )
EOF
@@ -142,5 +142,4 @@
(
this.Context == input.Context ||
(this.Context != null &&
this.Context.Equals(input.Context))
(this.Context != null && this.Context.Equals(input.Context)) ||
(this.Context == null && input.Context == null)
)
Copilot is powered by AI and may make mistakes. Always verify output.
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as ForbiddenResponse);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

ForbiddenResponse.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of ForbiddenResponse.

Copilot Autofix

AI 11 months ago

To fix the problem, we need to replace the use of as in the Equals method with a type check using GetType(). This ensures that the Equals method only returns true if the objects being compared are of the exact same type.

  • Replace the line return this.Equals(input as ForbiddenResponse); with a type check using GetType().
  • Ensure that the Equals method correctly handles the comparison by checking the type of the input object.
Suggested changeset 1
src/OpenFga.Sdk/Model/ForbiddenResponse.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/ForbiddenResponse.cs b/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
--- a/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
+++ b/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
@@ -87,3 +87,6 @@
         public override bool Equals(object input) {
-            return this.Equals(input as ForbiddenResponse);
+            if (input == null || this.GetType() != input.GetType()) {
+                return false;
+            }
+            return this.Equals((ForbiddenResponse)input);
         }
EOF
@@ -87,3 +87,6 @@
public override bool Equals(object input) {
return this.Equals(input as ForbiddenResponse);
if (input == null || this.GetType() != input.GetType()) {
return false;
}
return this.Equals((ForbiddenResponse)input);
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +101 to +110
(
this.Code == input.Code ||
this.Code.Equals(input.Code)
) &&
(
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.

Copilot Autofix

AI 11 months ago

To fix the problem, we should break down the complex condition into smaller, more manageable parts. This can be achieved by introducing intermediate boolean variables that represent parts of the condition. This approach will make the code easier to read and understand.

Specifically, we will:

  1. Extract the conditions involving this.Code and input.Code into a separate boolean variable.
  2. Extract the conditions involving this.Message and input.Message into another boolean variable.
  3. Extract the condition involving this.AdditionalProperties and input.AdditionalProperties into a third boolean variable.
  4. Combine these boolean variables in the final return statement.
Suggested changeset 1
src/OpenFga.Sdk/Model/ForbiddenResponse.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/ForbiddenResponse.cs b/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
--- a/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
+++ b/src/OpenFga.Sdk/Model/ForbiddenResponse.cs
@@ -99,13 +99,7 @@
             }
-            return
-                (
-                    this.Code == input.Code ||
-                    this.Code.Equals(input.Code)
-                ) &&
-                (
-                    this.Message == input.Message ||
-                    (this.Message != null &&
-                    this.Message.Equals(input.Message))
-                )
-                && (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
+            bool codesEqual = this.Code == input.Code || this.Code.Equals(input.Code);
+            bool messagesEqual = this.Message == input.Message || (this.Message != null && this.Message.Equals(input.Message));
+            bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any();
+
+            return codesEqual && messagesEqual && additionalPropertiesEqual;
         }
EOF
@@ -99,13 +99,7 @@
}
return
(
this.Code == input.Code ||
this.Code.Equals(input.Code)
) &&
(
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
bool codesEqual = this.Code == input.Code || this.Code.Equals(input.Code);
bool messagesEqual = this.Message == input.Message || (this.Message != null && this.Message.Equals(input.Message));
bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any();

return codesEqual && messagesEqual && additionalPropertiesEqual;
}
Copilot is powered by AI and may make mistakes. Always verify output.
@rhamzeh rhamzeh force-pushed the chore/sync-generator-changes branch from ad53591 to 1e61936 Compare March 28, 2025 20:06
@rhamzeh rhamzeh force-pushed the chore/sync-generator-changes branch from 1e61936 to 0e362cb Compare April 21, 2025 13:54
Comment on lines 1427 to +1430
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.NotFound,
Content = Utils.CreateJsonStringContent(new Object { }),
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = false }),
});

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning test

Disposable 'HttpResponseMessage' is created but not disposed.

Copilot Autofix

AI 10 months ago

The best way to fix the issue is to ensure that the HttpResponseMessage objects are properly disposed of after use. Since the ReturnsAsync method in Moq does not provide a built-in mechanism for automatic disposal, we can use a using block to wrap the creation of each HttpResponseMessage object. This ensures that the objects are disposed of as soon as they go out of scope.

To implement this:

  1. Replace the inline creation of HttpResponseMessage objects in the SetupSequence method with a lambda function that creates and returns the response within a using block.
  2. This approach ensures that each HttpResponseMessage is properly disposed of after being returned.

Suggested changeset 1
src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs b/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
--- a/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
+++ b/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
@@ -1495,17 +1495,29 @@
             )
-            .ReturnsAsync(new HttpResponseMessage() {
-                StatusCode = HttpStatusCode.OK,
-                Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
+            .ReturnsAsync(() => {
+                using var response = new HttpResponseMessage() {
+                    StatusCode = HttpStatusCode.OK,
+                    Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
+                };
+                return response;
             })
-            .ReturnsAsync(new HttpResponseMessage() {
-                StatusCode = HttpStatusCode.OK,
-                Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = false }),
+            .ReturnsAsync(() => {
+                using var response = new HttpResponseMessage() {
+                    StatusCode = HttpStatusCode.OK,
+                    Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = false }),
+                };
+                return response;
             })
-            .ReturnsAsync(new HttpResponseMessage() {
-                StatusCode = HttpStatusCode.OK,
-                Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
+            .ReturnsAsync(() => {
+                using var response = new HttpResponseMessage() {
+                    StatusCode = HttpStatusCode.OK,
+                    Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
+                };
+                return response;
             })
-            .ReturnsAsync(new HttpResponseMessage() {
-                StatusCode = HttpStatusCode.NotFound,
-                Content = Utils.CreateJsonStringContent(new Object { }),
+            .ReturnsAsync(() => {
+                using var response = new HttpResponseMessage() {
+                    StatusCode = HttpStatusCode.NotFound,
+                    Content = Utils.CreateJsonStringContent(new Object { }),
+                };
+                return response;
             });
EOF
@@ -1495,17 +1495,29 @@
)
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
.ReturnsAsync(() => {
using var response = new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
};
return response;
})
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = false }),
.ReturnsAsync(() => {
using var response = new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = false }),
};
return response;
})
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
.ReturnsAsync(() => {
using var response = new HttpResponseMessage() {
StatusCode = HttpStatusCode.OK,
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
};
return response;
})
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.NotFound,
Content = Utils.CreateJsonStringContent(new Object { }),
.ReturnsAsync(() => {
using var response = new HttpResponseMessage() {
StatusCode = HttpStatusCode.NotFound,
Content = Utils.CreateJsonStringContent(new Object { }),
};
return response;
});
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +1492 to +1495
Content = Utils.CreateJsonStringContent(new CheckResponse { Allowed = true }),
})
.ReturnsAsync(new HttpResponseMessage() {
StatusCode = HttpStatusCode.NotFound,

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning test

Disposable 'HttpResponseMessage' is created but not disposed.
Task<ListRelationsResponse> ApiError() => fgaClient.ListRelations(body, options);
var error = await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError);

mockHandler.Protected().Verify(

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
error
is useless, since its value is never read.

Copilot Autofix

AI 10 months ago

To fix the issue, the assignment to the error variable should be removed, leaving only the await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError) call. This ensures that the test remains functional while eliminating the redundant assignment. No additional changes are required, as the test's purpose is already fulfilled by the Assert.ThrowsAsync call.


Suggested changeset 1
src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs b/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
--- a/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
+++ b/src/OpenFga.Sdk.Test/Client/OpenFgaClientTests.cs
@@ -1530,3 +1530,3 @@
         Task<ListRelationsResponse> ApiError() => fgaClient.ListRelations(body, options);
-        var error = await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError);
+        await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError);
 
EOF
@@ -1530,3 +1530,3 @@
Task<ListRelationsResponse> ApiError() => fgaClient.ListRelations(body, options);
var error = await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError);
await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError);

Copilot is powered by AI and may make mistakes. Always verify output.

/// <inheritdoc />
public override bool Equals(object obj) {
if (obj is BatchCheckSingleResponse other) {

Check warning

Code scanning / CodeQL

Equals should not apply "is" Warning

BatchCheckSingleResponse.Equals(object) should not use "is" on its parameter, as it will not work properly for subclasses of BatchCheckSingleResponse.

Copilot Autofix

AI 10 months ago

To fix the issue, replace the is operator in the Equals(object obj) method with a type comparison using GetType(). This ensures that the method only evaluates equality for objects of the exact same type as the current instance. Specifically:

  1. Replace the if (obj is BatchCheckSingleResponse other) check with a if (obj == null || GetType() != obj.GetType()) check.
  2. Cast the obj parameter to BatchCheckSingleResponse after confirming the type match.

This change ensures that the Equals method adheres to the symmetry and transitivity requirements of the equality contract.


Suggested changeset 1
src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs b/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
--- a/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
+++ b/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
@@ -68,6 +68,7 @@
     public override bool Equals(object obj) {
-        if (obj is BatchCheckSingleResponse other) {
-            return Equals(other);
+        if (obj == null || GetType() != obj.GetType()) {
+            return false;
         }
-        return false;
+        var other = (BatchCheckSingleResponse)obj;
+        return Equals(other);
     }
EOF
@@ -68,6 +68,7 @@
public override bool Equals(object obj) {
if (obj is BatchCheckSingleResponse other) {
return Equals(other);
if (obj == null || GetType() != obj.GetType()) {
return false;
}
return false;
var other = (BatchCheckSingleResponse)obj;
return Equals(other);
}
Copilot is powered by AI and may make mistakes. Always verify output.

/// <inheritdoc />
public override bool Equals(object obj) {
if (obj is ClientBatchCheckClientResponse other) {

Check warning

Code scanning / CodeQL

Equals should not apply "is" Warning

ClientBatchCheckClientResponse.Equals(object) should not use "is" on its parameter, as it will not work properly for subclasses of ClientBatchCheckClientResponse.

Copilot Autofix

AI 10 months ago

To fix the issue, we will replace the use of the is operator in the Equals(object obj) method with a type comparison using GetType(). This ensures that the method only returns true if the obj parameter is of the exact same type as the current instance. Specifically:

  1. Replace the if (obj is ClientBatchCheckClientResponse other) check with if (obj != null && obj.GetType() == GetType()).
  2. Cast obj to ClientBatchCheckClientResponse after confirming the type match.

This change ensures that the Equals method adheres to the symmetry and transitivity requirements of the Equals contract.


Suggested changeset 1
src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs b/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
--- a/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
+++ b/src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
@@ -115,3 +115,4 @@
     public override bool Equals(object obj) {
-        if (obj is ClientBatchCheckClientResponse other) {
+        if (obj != null && obj.GetType() == GetType()) {
+            var other = (ClientBatchCheckClientResponse)obj;
             return Equals(other);
EOF
@@ -115,3 +115,4 @@
public override bool Equals(object obj) {
if (obj is ClientBatchCheckClientResponse other) {
if (obj != null && obj.GetType() == GetType()) {
var other = (ClientBatchCheckClientResponse)obj;
return Equals(other);
Copilot is powered by AI and may make mistakes. Always verify output.
(
ContextualTuples == input.ContextualTuples ||
(ContextualTuples != null &&
ContextualTuples.Equals(input.ContextualTuples))

Check notice

Code scanning / CodeQL

Equals on collections Note

Using Equals(object) on a collection only checks reference equality.

Copilot Autofix

AI 10 months ago

To fix the issue, replace the Equals call on ContextualTuples with a call to SequenceEqual. This ensures that the comparison is performed element-by-element, which is the intended behavior. The SequenceEqual method is part of LINQ, so ensure that the System.Linq namespace is imported.

Changes to make:

  1. Replace the ContextualTuples.Equals(input.ContextualTuples) call with ContextualTuples.SequenceEqual(input.ContextualTuples).
  2. Add a null check for input.ContextualTuples before calling SequenceEqual to avoid a NullReferenceException.

Suggested changeset 1
src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs b/src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs
--- a/src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs
+++ b/src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs
@@ -17,3 +17,3 @@
 using System.Text.Json.Serialization;
-
+using System.Linq;
 namespace OpenFga.Sdk.Client.Model;
@@ -76,3 +76,4 @@
                 (ContextualTuples != null &&
-                 ContextualTuples.Equals(input.ContextualTuples))
+                 input.ContextualTuples != null &&
+                 ContextualTuples.SequenceEqual(input.ContextualTuples))
             );
EOF
@@ -17,3 +17,3 @@
using System.Text.Json.Serialization;

using System.Linq;
namespace OpenFga.Sdk.Client.Model;
@@ -76,3 +76,4 @@
(ContextualTuples != null &&
ContextualTuples.Equals(input.ContextualTuples))
input.ContextualTuples != null &&
ContextualTuples.SequenceEqual(input.ContextualTuples))
);
Copilot is powered by AI and may make mistakes. Always verify output.
public static ClientListStoresRequest FromJson(string jsonString) =>
JsonSerializer.Deserialize<ClientListStoresRequest>(jsonString) ?? throw new InvalidOperationException();

public override bool Equals(object input) => Equals(input as ClientListStoresRequest);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

ClientListStoresRequest.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of ClientListStoresRequest.

Copilot Autofix

AI 10 months ago

To fix the issue, replace the use of the as operator in the Equals(object input) method with a type check using GetType() to ensure that the input object is of the exact same type as the current instance. This approach avoids the pitfalls of the as operator and ensures that the equality comparison adheres to the expected behavior.

Specifically:

  1. Replace input as ClientListStoresRequest with a type check using GetType() and a cast.
  2. Ensure that the method returns false if the types do not match.

The updated Equals(object input) method will first check if the input object is of the same type as the current instance using GetType(). If the types match, it will cast the input object to ClientListStoresRequest and delegate the comparison to the Equals(ClientListStoresRequest input) method.


Suggested changeset 1
src/OpenFga.Sdk/Client/Model/ClientListStoresRequest.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Client/Model/ClientListStoresRequest.cs b/src/OpenFga.Sdk/Client/Model/ClientListStoresRequest.cs
--- a/src/OpenFga.Sdk/Client/Model/ClientListStoresRequest.cs
+++ b/src/OpenFga.Sdk/Client/Model/ClientListStoresRequest.cs
@@ -59,3 +59,8 @@
 
-    public override bool Equals(object input) => Equals(input as ClientListStoresRequest);
+    public override bool Equals(object input) {
+        if (input == null || GetType() != input.GetType()) {
+            return false;
+        }
+        return Equals((ClientListStoresRequest)input);
+    }
 
EOF
@@ -59,3 +59,8 @@

public override bool Equals(object input) => Equals(input as ClientListStoresRequest);
public override bool Equals(object input) {
if (input == null || GetType() != input.GetType()) {
return false;
}
return Equals((ClientListStoresRequest)input);
}

Copilot is powered by AI and may make mistakes. Always verify output.
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as BatchCheckItem);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

BatchCheckItem.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of BatchCheckItem.

Copilot Autofix

AI 10 months ago

To fix the issue, we will replace the use of as in the Equals(object input) method with a type check using GetType(). Specifically:

  1. Check if the input object is null or if its runtime type is not equal to the runtime type of the current object (this).
  2. If the type check fails, return false. Otherwise, cast the input object to BatchCheckItem using a direct cast and proceed with the equality comparison.

This ensures that the Equals method adheres to the symmetry and transitivity requirements and avoids issues with subclassing.


Suggested changeset 1
src/OpenFga.Sdk/Model/BatchCheckItem.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/BatchCheckItem.cs b/src/OpenFga.Sdk/Model/BatchCheckItem.cs
--- a/src/OpenFga.Sdk/Model/BatchCheckItem.cs
+++ b/src/OpenFga.Sdk/Model/BatchCheckItem.cs
@@ -117,3 +117,6 @@
         public override bool Equals(object input) {
-            return this.Equals(input as BatchCheckItem);
+            if (input == null || input.GetType() != this.GetType()) {
+                return false;
+            }
+            return this.Equals((BatchCheckItem)input);
         }
EOF
@@ -117,3 +117,6 @@
public override bool Equals(object input) {
return this.Equals(input as BatchCheckItem);
if (input == null || input.GetType() != this.GetType()) {
return false;
}
return this.Equals((BatchCheckItem)input);
}
Copilot is powered by AI and may make mistakes. Always verify output.
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as BatchCheckResponse);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

BatchCheckResponse.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of BatchCheckResponse.

Copilot Autofix

AI 10 months ago

To fix the issue, we will replace the use of the as operator in the Equals(object input) method with a type check using GetType(). This ensures that the method only considers objects of the exact same type as the current instance. Specifically:

  1. Replace input as BatchCheckResponse with a type check using GetType() to ensure strict type equality.
  2. Update the method to return false if the types do not match.

Suggested changeset 1
src/OpenFga.Sdk/Model/BatchCheckResponse.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/BatchCheckResponse.cs b/src/OpenFga.Sdk/Model/BatchCheckResponse.cs
--- a/src/OpenFga.Sdk/Model/BatchCheckResponse.cs
+++ b/src/OpenFga.Sdk/Model/BatchCheckResponse.cs
@@ -79,3 +79,6 @@
         public override bool Equals(object input) {
-            return this.Equals(input as BatchCheckResponse);
+            if (input == null || this.GetType() != input.GetType()) {
+                return false;
+            }
+            return this.Equals((BatchCheckResponse)input);
         }
EOF
@@ -79,3 +79,6 @@
public override bool Equals(object input) {
return this.Equals(input as BatchCheckResponse);
if (input == null || this.GetType() != input.GetType()) {
return false;
}
return this.Equals((BatchCheckResponse)input);
}
Copilot is powered by AI and may make mistakes. Always verify output.
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as BatchCheckSingleResult);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

BatchCheckSingleResult.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of BatchCheckSingleResult.

Copilot Autofix

AI 10 months ago

To fix the issue, the Equals(object input) method should be updated to compare the runtime type of the input object with the type of the current instance using GetType(). This ensures that the method only considers objects of the exact same type as equal. The as operator should be replaced with a direct type check and cast.

Specifically:

  1. Replace the input as BatchCheckSingleResult cast with a check that compares input.GetType() to this.GetType().
  2. If the types match, cast input to BatchCheckSingleResult using a direct cast and proceed with the equality comparison.
  3. If the types do not match, return false.

Suggested changeset 1
src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs b/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
--- a/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
+++ b/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
@@ -88,3 +88,6 @@
         public override bool Equals(object input) {
-            return this.Equals(input as BatchCheckSingleResult);
+            if (input == null || input.GetType() != this.GetType()) {
+                return false;
+            }
+            return this.Equals((BatchCheckSingleResult)input);
         }
EOF
@@ -88,3 +88,6 @@
public override bool Equals(object input) {
return this.Equals(input as BatchCheckSingleResult);
if (input == null || input.GetType() != this.GetType()) {
return false;
}
return this.Equals((BatchCheckSingleResult)input);
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +102 to +111
(
this.Allowed == input.Allowed ||
this.Allowed.Equals(input.Allowed)
) &&
(
this.Error == input.Error ||
(this.Error != null &&
this.Error.Equals(input.Error))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.

Copilot Autofix

AI 10 months ago

To fix the issue, we will simplify the complex condition on line 102 by breaking it into smaller, named boolean expressions. Each sub-condition will be assigned to a descriptive variable, making the overall logic easier to follow. This approach will not change the functionality of the code but will improve its readability and maintainability.

Suggested changeset 1
src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs b/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
--- a/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
+++ b/src/OpenFga.Sdk/Model/BatchCheckSingleResult.cs
@@ -100,13 +100,8 @@
             }
-            return
-                (
-                    this.Allowed == input.Allowed ||
-                    this.Allowed.Equals(input.Allowed)
-                ) &&
-                (
-                    this.Error == input.Error ||
-                    (this.Error != null &&
-                    this.Error.Equals(input.Error))
-                )
-                && (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
+            bool allowedEquals = this.Allowed == input.Allowed || this.Allowed.Equals(input.Allowed);
+            bool errorEquals = this.Error == input.Error || (this.Error != null && this.Error.Equals(input.Error));
+            bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count &&
+                                             !this.AdditionalProperties.Except(input.AdditionalProperties).Any();
+
+            return allowedEquals && errorEquals && additionalPropertiesEqual;
         }
EOF
@@ -100,13 +100,8 @@
}
return
(
this.Allowed == input.Allowed ||
this.Allowed.Equals(input.Allowed)
) &&
(
this.Error == input.Error ||
(this.Error != null &&
this.Error.Equals(input.Error))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
bool allowedEquals = this.Allowed == input.Allowed || this.Allowed.Equals(input.Allowed);
bool errorEquals = this.Error == input.Error || (this.Error != null && this.Error.Equals(input.Error));
bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count &&
!this.AdditionalProperties.Except(input.AdditionalProperties).Any();

return allowedEquals && errorEquals && additionalPropertiesEqual;
}
Copilot is powered by AI and may make mistakes. Always verify output.
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as CheckError);

Check warning

Code scanning / CodeQL

Equals should not apply "as" Warning

CheckError.Equals(object) should not use "as" on its parameter, as it will not work properly for subclasses of CheckError.

Copilot Autofix

AI 10 months ago

To fix the issue, the Equals(object input) method should be updated to use GetType() to compare the runtime type of the input object with the type of the current instance. This ensures that the comparison is only performed if the objects are of the exact same type. The as operator should be replaced with a direct type check and cast.

Specifically:

  1. Replace the line return this.Equals(input as CheckError); with a type check using GetType() and a direct cast.
  2. Ensure that the Equals(CheckError input) method is only called if the type check passes.

Suggested changeset 1
src/OpenFga.Sdk/Model/CheckError.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/CheckError.cs b/src/OpenFga.Sdk/Model/CheckError.cs
--- a/src/OpenFga.Sdk/Model/CheckError.cs
+++ b/src/OpenFga.Sdk/Model/CheckError.cs
@@ -96,3 +96,6 @@
         public override bool Equals(object input) {
-            return this.Equals(input as CheckError);
+            if (input == null || input.GetType() != this.GetType()) {
+                return false;
+            }
+            return this.Equals((CheckError)input);
         }
EOF
@@ -96,3 +96,6 @@
public override bool Equals(object input) {
return this.Equals(input as CheckError);
if (input == null || input.GetType() != this.GetType()) {
return false;
}
return this.Equals((CheckError)input);
}
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +110 to +123
(
this.InputError == input.InputError ||
this.InputError.Equals(input.InputError)
) &&
(
this.InternalError == input.InternalError ||
this.InternalError.Equals(input.InternalError)
) &&
(
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());

Check notice

Code scanning / CodeQL

Complex condition Note

Complex condition: too many logical operations in this expression.

Copilot Autofix

AI 10 months ago

To address the complexity of the condition, we will break it into smaller, named boolean expressions. Each sub-condition will be assigned to a descriptive variable, making the overall logic easier to follow. This approach will not alter the functionality but will improve readability and maintainability.

The changes will involve:

  1. Extracting each logical sub-condition into a separate boolean variable with a meaningful name.
  2. Combining these variables in the final return statement to preserve the original logic.
Suggested changeset 1
src/OpenFga.Sdk/Model/CheckError.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/OpenFga.Sdk/Model/CheckError.cs b/src/OpenFga.Sdk/Model/CheckError.cs
--- a/src/OpenFga.Sdk/Model/CheckError.cs
+++ b/src/OpenFga.Sdk/Model/CheckError.cs
@@ -108,17 +108,8 @@
             }
-            return
-                (
-                    this.InputError == input.InputError ||
-                    this.InputError.Equals(input.InputError)
-                ) &&
-                (
-                    this.InternalError == input.InternalError ||
-                    this.InternalError.Equals(input.InternalError)
-                ) &&
-                (
-                    this.Message == input.Message ||
-                    (this.Message != null &&
-                    this.Message.Equals(input.Message))
-                )
-                && (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
+            bool inputErrorEquals = this.InputError == input.InputError || this.InputError.Equals(input.InputError);
+            bool internalErrorEquals = this.InternalError == input.InternalError || this.InternalError.Equals(input.InternalError);
+            bool messageEquals = this.Message == input.Message || (this.Message != null && this.Message.Equals(input.Message));
+            bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any();
+
+            return inputErrorEquals && internalErrorEquals && messageEquals && additionalPropertiesEqual;
         }
EOF
@@ -108,17 +108,8 @@
}
return
(
this.InputError == input.InputError ||
this.InputError.Equals(input.InputError)
) &&
(
this.InternalError == input.InternalError ||
this.InternalError.Equals(input.InternalError)
) &&
(
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
bool inputErrorEquals = this.InputError == input.InputError || this.InputError.Equals(input.InputError);
bool internalErrorEquals = this.InternalError == input.InternalError || this.InternalError.Equals(input.InternalError);
bool messageEquals = this.Message == input.Message || (this.Message != null && this.Message.Equals(input.Message));
bool additionalPropertiesEqual = this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any();

return inputErrorEquals && internalErrorEquals && messageEquals && additionalPropertiesEqual;
}
Copilot is powered by AI and may make mistakes. Always verify output.
@rhamzeh rhamzeh added this pull request to the merge queue May 9, 2025
Merged via the queue into main with commit 2c79124 May 9, 2025
14 checks passed
@rhamzeh rhamzeh deleted the chore/sync-generator-changes branch May 9, 2025 13:10
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.

Support passing name filter to ListStores .NET SDK: ListRelations should not swallow errors if an underlying check errors out #183

7 participants

Comments