-
Notifications
You must be signed in to change notification settings - Fork 717
Single-quote OData strings within parentheses syntax #1153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| foreach ( var parameter in function.Parameters ) | ||
| { | ||
| if ( parameter.Type.IsString() ) | ||
| { | ||
| names ??= []; | ||
| names.Add( parameterMappings[parameter.Name] ); | ||
| } | ||
| } |
Check notice
Code scanning / CodeQL
Missed opportunity to use Where Note
implicitly filters its target sequence
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 8 hours ago
In general terms, to fix this, replace the explicit in-loop if-statement filtering (if (condition) { ... }) with filtration of the enumeration using LINQ's Where before entering the loop. Specifically, for the loop at line 538:
foreach ( var parameter in function.Parameters )
{
if ( parameter.Type.IsString() )
{
names ??= [];
names.Add( parameterMappings[parameter.Name] );
}
}should become:
foreach ( var parameter in function.Parameters.Where(p => p.Type.IsString()) )
{
names ??= [];
names.Add( parameterMappings[parameter.Name] );
}This makes it clear that we're only iterating over parameters with Type.IsString(). To implement the change, you'll need to add using System.Linq; if it's not already present. Only code shown may be modified: you may add the import at the top if and only if it's missing in the lines shown.
-
Copy modified line R20 -
Copy modified line R539 -
Copy modified lines R541-R542
| @@ -17,6 +17,7 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Text; | ||
| using System.Linq; | ||
| using static ODataMetadataOptions; | ||
| using static System.StringComparison; | ||
| using Opts = Microsoft.Extensions.Options.Options; | ||
| @@ -535,13 +536,10 @@ | ||
| IDictionary<string, string> parameterMappings, | ||
| ref HashSet<string>? names ) | ||
| { | ||
| foreach ( var parameter in function.Parameters ) | ||
| foreach ( var parameter in function.Parameters.Where(p => p.Type.IsString()) ) | ||
| { | ||
| if ( parameter.Type.IsString() ) | ||
| { | ||
| names ??= []; | ||
| names.Add( parameterMappings[parameter.Name] ); | ||
| } | ||
| names ??= []; | ||
| names.Add( parameterMappings[parameter.Name] ); | ||
| } | ||
| } | ||
|
|
Single-quote OData strings
Description
Fixes up OData route templates during API exploration for OData strings that are within the parentheses syntax. This typically applies to composite keys and functions.