-
Notifications
You must be signed in to change notification settings - Fork 228
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
Fix nodes merging to update children paths and path parameters #4174
Conversation
The integration tests are reporting some failures we have to decide how to tackle:
|
Thanks for looking into this.
This change won't have performance impacts however (actually it'll be the other way around) I do believe we should keep the merging, but fix it so it works as expected for subnodes and so on. |
Do you have something in mind? To keep the merging we need anyhow to generate new "SegmentParameterNames" and I'm not able to come up with a heuristic proposal that is not going to fail on edge cases. |
I think the problem lies in the fact the method needs to be splat. It's mixing concerns of detecting nodes to merge, and applying the replacement to a whole branch. |
We might also take this opportunity to move that method outside of the request builder to ease up testability. I'll try to start looking at that momentarily (once I get to the never-ending list of GitHub notifications) |
Agreed, I'll wait for your follow-up, I might be missing something. |
I have just force pushed to this PR, at this point the unit test you've added still fails, but this is expected as I didn't change the logic yet. |
I've just pushed another patch here that fixes a couple of things:
I don't think the changes implemented here would lead to any breaking changes in the vast majority of cases. As you know I have personal things going on right now that prevent me from giving this my 100%, so here are my requests:
Thanks for the help in all this! |
Just to confirm, the changes result in no diff in graph SDKs (tested with Java,Go,C#) so no regressions introduced from that side. From the looks of it, it also should have no impact on classes (as indexer requestBuilder classes get normalized as a |
For full transparency, I'm a bit busy today, but I'll try to target the comments by the end of Mon 👍 on my TODO. |
tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs
Show resolved
Hide resolved
- fixes deduplication algo not renaming child paths and parameter names
Signed-off-by: Vincent Biret <[email protected]>
I have just pushed a couple of updates:
The integration test seems to be building except for an instance of #3398 at it\java\src\apisdk\repos\item\item\autolinks\AutolinksPostRequestBody.java:33 (remove the quotes after generation). Let me know what you think, I believe we're getting close to a final resolution on this one. |
Thanks for the update @baywet I'll have a closer look tomorrow! |
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 reviewed the PR, and I genuinely appreciate your effort to address this issue while maintaining the current design, @baywet.
However, I believe the outcome still falls short of delivering an optimal user experience and may result in a confusing fluent API.
I may not fully grasp the underlying reason for merging the nodes. Could you kindly explain it to me again? 🙏
I'll be away until Monday. If you proceed with these changes in my absence, I kindly request that you thoroughly document this behavior at the very least.
tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs
Show resolved
Hide resolved
@andreaTP thank you for the continuous feedback on this one. On merging the nodesA description with ambiguous path items is invalid according to the specification. We could perfectly say to the user "sorry, your spec is invalid, fix it first", but experience has shown this is hostile to API consumers who don't necessarily understand the semantics of OpenAPI, don't want to maintain a copy of the description, etc... The other reason why we're merging the nodes is because it's impossible to have multiple indexers of the same types on the same class in C#. We could perfectly go a different route and replace those indexers by methods with specific names so they don't collide, but I believe this gets us further from the specification's intent to have a consistent API path segmentation. Maybe @darrelmiller could weight in on this one. The alphabetical selectionThis is simply because I couldn't come up with a better rationale, other than using a language library and running words proximity with the previous path segment, which would be costly and sometimes unpredictable. At least it's easy to understand and fast this way. The id suffixOn this one I'm open to stop appending it, no hard opinion on the matter. Additional casesReviewing the specification, I noticed there might be cases we haven't talked about:
|
Thanks for the feedback!
This is a bit dissimilar to how I read the spec, and explained on the top my interpretation. I might be wrong, but I would love feedback from @darrelmiller on this one. Achieving consensus on this aspect is probably key to move forward the discussion. I'm out till Mon, if you want to merge this one as is, since it's anyhow a step forward, I don't oppose; but I would love to keep the conversation going. |
Notes from a conversation between myself and @baywet The current OpenAPI specification says that the following is invalid
However, I expect future iterations of the specification will relax this constraint and we know that these already exist in the wild. The notion of a collection of things having multiple candidate keys is a common concept and we should be able to model this. We currently model these parameter segments as a CodeIndexer DOM model. Currently the CodeIndexer doesn't support the notion of alternate keys. We think it is worth exploring adding support for alternate keys to the CodeIndexer. We can continue to use the first parameter alphabetically as the default primary key, and all other parameters as alternate keys. This allows us to introduce support for a x-primary-key hint in the OpenAPI description that enables a particular path to be stable in its use of syntax like the C# indexer. It may be possible that different candidate keys return different types. From a logical perspective the different types should be closely related, but from code perspective the types could be different. This does warp the concept of CodeIndexer slightly, but may be tolerable. Adding this notion of candidate/alternate keys to the code indexer would remove the need for merging of nodes and the language refiners can emit specific named indexer methods for alternate keys and some default indexer method for the primary key, or they can emit specific named indexer methods for all the candidate keys. |
Thanks a lot @darrelmiller for chiming in, appreciated! I think that this statement is enough to me:
Please proceed with the implementation in this PR which reflects the current state of the art and we will iterate next. Thanks a lot for bearing with me on this @baywet ! |
This comment was marked as spam.
This comment was marked as spam.
@baywet I noticed this failure on this PR: Do you already have an issue tracking it? |
Merged, and created #4241 |
@andreaTP see this comment #4174 (comment) |
After much thinking about it, I believe that this is the correct solution even if it might have performance implications.
Fixes #4151
fixes #4085 .
What's happening?
The
MergeIndexNodesAtSameLevel
deduplicates endpoints containing different path parameters forcing their name to become{entity-id}
.Why?
The specification seems to indicate that this pattern is invalid.
I tend to believe that this section is slightly under-specified, as it doesn't clearly state what should happen when the path parameter names are diverging, and, the matching of the path template is unique, e.g.:
cc. Maybe @darrelmiller can shed light on this
Current tradeoff
Under the assumption that the Path Templating Matching is invalid when the names of path segments are diverging the current optimization of merging the index nodes can be performed.
This will somehow also "help" as @baywet mentioned:
I believe that the current approach is misleading as we tend to agree that the path parameter names should be preserved and we got reports about collision issues with small and large API definitions.
Proposed solution
Assuming that:
user/users-id
,foo/users
andtemplate_owner/owner
at the same time)Simply removing the merge function, we will be more closely mapping the original OpenAPI definition and avoiding this entire class of issues.