-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fixes functions with parameters in Go #1681
Conversation
CodeSnippetsReflection.OpenAPI/LanguageGenerators/GoGenerator.cs
Outdated
Show resolved
Hide resolved
CodeSnippetsReflection.OpenAPI/LanguageGenerators/GoGenerator.cs
Outdated
Show resolved
Hide resolved
{ | ||
|
||
private static readonly Regex FunctionWithParams = new(@"^(\w+)\(([^)]+)\)$", RegexOptions.Compiled, TimeSpan.FromMilliseconds(200)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this is here and not using the FunctionWithParameterRegex
in line 19?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The need here was to extract the parameters used in the example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've combined these 2 since the existing regex both identify a function syntax. The difference is the new regex splits the function into "name" + "params" and make it simpler to return function names.
if (!funcWithParams.Item1) | ||
return x.Segment.ToFirstCharacterUpperCase() + "()."; | ||
|
||
var varName = funcWithParams.Item3.FirstOrDefault().Key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple parameters is a possiblity that is not catered for.
Example at https://learn.microsoft.com/en-us/graph/api/callrecords-callrecord-getpstncalls?view=graph-rest-1.0&tabs=http
return x.Segment.ToFirstCharacterUpperCase() + "()."; | ||
else | ||
{ | ||
var funcWithParams = x.Segment.GetFunctionWithParameters(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all you need to do here is call x.Segment.IsFunctionWithParameters()
(already defined) then look up the parameters and values in snippetCodeGraph.PathParameters
as
- Functions with multiple parameters could exists
- The
snippetCodeGraph.PathParameters
in contains type information that you can use to know for scenarios where the parameter is a number/Date type - Casing is consistent with the metadata therefore generating names that are aligned with the generated SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. One concern with the Path Parameter is we can have an example using 1 or 2 params instead of all the path parameters. Thats the reason I opted for extracting the parameters from the snippet. I however do agree that the path param will give better type information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a path had 3 parameters, and the example would use only 2 parameters, that would mean that one of the parameters is optional or has a pre-defined default. In such a case i believe the metadata would either
- have two distinct paths (one with the optional param and the other without).
- one path but the default would still need to be generated/passed as Kiota will still generate the parameter name in the function Handling of optional function parameters microsoft/kiota#2584
At this point of the snippet generation, the example path would already have been matched to the path that is relevant to it (when the snippet model is built) and every path parameter (including the optional ones if matched with their defaults) would be needed to be generated as only one url template is present and a parameter must be passed/included in function name.
Using the http URL would generate a function that does not exist in the SDK in such a scenario as the default parameter would be missing/not passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only left concern would be is it a given than the function with params is always the last segment of a path? This approach ensures that the params retain the position in the segment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't always be the last segment. But that is catered for as the operation can be checked on the specific segment as we traverse through the segments in the paths. Yes?
With the key values, you could still lookup casing/types from the snippetCodeGraph.PathParameters
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest updates break some tests in PHP/C#/Poweshell.
Any chance we can
- Fix the broken test.
- Add a test for Go for the test thats broken. Should point to the snippet at https://learn.microsoft.com/en-us/graph/api/callrecords-callrecord-getpstncalls?view=graph-rest-1.0&tabs=http
CodeSnippetsReflection.OpenAPI/LanguageGenerators/GoGenerator.cs
Outdated
Show resolved
Hide resolved
6160ec3
to
054bd35
Compare
Kudos, SonarCloud Quality Gate passed! |
Overview
Fixes generation fluent path in go for functions with paramerts e.g https://learn.microsoft.com/en-us/graph/api/reportroot-getyammeractivitycounts?view=graph-rest-1.0&tabs=http
Current behaviour
expected behaviour
Testing Instructions