Conversation
Codecov ReportAttention: Patch coverage is
❌ 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. 🚀 New features to boost your workflow:
|
| 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
Show autofix suggestion
Hide autofix suggestion
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.Contextwith a value comparison using theEqualsmethod. - Ensure that the
Equalsmethod is called only whenthis.Contextis not null to avoid potentialNullReferenceException.
| @@ -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) | ||
| ) |
| /// <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
Show autofix suggestion
Hide autofix suggestion
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 usingGetType(). - Ensure that the
Equalsmethod correctly handles the comparison by checking the type of the input object.
| @@ -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); | ||
| } |
| ( | ||
| 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
Show autofix suggestion
Hide autofix suggestion
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:
- Extract the conditions involving
this.Codeandinput.Codeinto a separate boolean variable. - Extract the conditions involving
this.Messageandinput.Messageinto another boolean variable. - Extract the condition involving
this.AdditionalPropertiesandinput.AdditionalPropertiesinto a third boolean variable. - Combine these boolean variables in the final return statement.
| @@ -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; | ||
| } |
ad53591 to
1e61936
Compare
…II in OpenFGA Generator PR: openfga/sdk-generator#433
This is in preparation to support server-side BatchCheck
1e61936 to
0e362cb
Compare
| .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
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the inline creation of
HttpResponseMessageobjects in theSetupSequencemethod with a lambda function that creates and returns the response within ausingblock. - This approach ensures that each
HttpResponseMessageis properly disposed of after being returned.
| @@ -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; | ||
| }); |
| 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
| 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -1530,3 +1530,3 @@ | ||
| Task<ListRelationsResponse> ApiError() => fgaClient.ListRelations(body, options); | ||
| var error = await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError); | ||
| await Assert.ThrowsAsync<FgaApiNotFoundError>(ApiError); | ||
|
|
|
|
||
| /// <inheritdoc /> | ||
| public override bool Equals(object obj) { | ||
| if (obj is BatchCheckSingleResponse other) { |
Check warning
Code scanning / CodeQL
Equals should not apply "is" Warning
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the
if (obj is BatchCheckSingleResponse other)check with aif (obj == null || GetType() != obj.GetType())check. - Cast the
objparameter toBatchCheckSingleResponseafter confirming the type match.
This change ensures that the Equals method adheres to the symmetry and transitivity requirements of the equality contract.
| @@ -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); | ||
| } |
|
|
||
| /// <inheritdoc /> | ||
| public override bool Equals(object obj) { | ||
| if (obj is ClientBatchCheckClientResponse other) { |
Check warning
Code scanning / CodeQL
Equals should not apply "is" Warning
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the
if (obj is ClientBatchCheckClientResponse other)check withif (obj != null && obj.GetType() == GetType()). - Cast
objtoClientBatchCheckClientResponseafter confirming the type match.
This change ensures that the Equals method adheres to the symmetry and transitivity requirements of the Equals contract.
| @@ -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); |
| ( | ||
| ContextualTuples == input.ContextualTuples || | ||
| (ContextualTuples != null && | ||
| ContextualTuples.Equals(input.ContextualTuples)) |
Check notice
Code scanning / CodeQL
Equals on collections Note
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the
ContextualTuples.Equals(input.ContextualTuples)call withContextualTuples.SequenceEqual(input.ContextualTuples). - Add a null check for
input.ContextualTuplesbefore callingSequenceEqualto avoid aNullReferenceException.
| @@ -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)) | ||
| ); |
| 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
Show autofix suggestion
Hide autofix suggestion
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:
- Replace
input as ClientListStoresRequestwith a type check usingGetType()and a cast. - Ensure that the method returns
falseif 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.
| @@ -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); | ||
| } | ||
|
|
| /// <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
Show autofix suggestion
Hide autofix suggestion
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:
- Check if the
inputobject isnullor if its runtime type is not equal to the runtime type of the current object (this). - If the type check fails, return
false. Otherwise, cast theinputobject toBatchCheckItemusing 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.
| @@ -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); | ||
| } |
| /// <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
Show autofix suggestion
Hide autofix suggestion
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:
- Replace
input as BatchCheckResponsewith a type check usingGetType()to ensure strict type equality. - Update the method to return
falseif the types do not match.
| @@ -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); | ||
| } |
| /// <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
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the
input as BatchCheckSingleResultcast with a check that comparesinput.GetType()tothis.GetType(). - If the types match, cast
inputtoBatchCheckSingleResultusing a direct cast and proceed with the equality comparison. - If the types do not match, return
false.
| @@ -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); | ||
| } |
| ( | ||
| 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
Show autofix suggestion
Hide autofix suggestion
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.
| @@ -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; | ||
| } |
| /// <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
Show autofix suggestion
Hide autofix suggestion
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:
- Replace the line
return this.Equals(input as CheckError);with a type check usingGetType()and a direct cast. - Ensure that the
Equals(CheckError input)method is only called if the type check passes.
| @@ -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); | ||
| } |
| ( | ||
| 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
Show autofix suggestion
Hide autofix suggestion
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:
- Extracting each logical sub-condition into a separate boolean variable with a meaningful name.
- Combining these variables in the final return statement to preserve the original logic.
| @@ -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; | ||
| } |
Description
This brings in several changes (and should not be squashed).
It will:
Note: This brings in all the API changes up to the most recent, however the wrapper
OpenFgaClientdoes not yet support server-sideBatchCheck. That will be in a followup PRReferences
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
mainGenerator PR: openfga/sdk-generator#420