-
Notifications
You must be signed in to change notification settings - Fork 221
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
AllOf C# Inheritence #5014
Comments
Hi @pettijohn If so, this is by design, in most scenarios allOf with single entries result from improper OAS description generation from the server-side tooling and was adding noise. This is why we decided to implement "squashing". Unless we get overwhelming feedback this is wrong, we're unlikely to change that at this point. |
Mostly correct. The schema has SIX components that extend I certainly understand and agree with your rationale for squashing when there is no added value. This is maybe a different case because there's value in the polymorphism and being able to treat everything as an This isn't my schema (again I'm getting it from Schwab). But maybe the solution is to modify the discriminator to reference the base class directly instead of through an abstraction that doesn't add any value. AccountsInstrument:
Here's a direct link to the open api schema: https://github.com/pettijohn/KiotaIssue/blob/95917e105b5e99533d164d43d12be52df71fe324/openapi3.json If you look at the latest version of the same file you can see how I added "ignorme" properties. I generated C# classes with this command (WSL, docker) https://github.com/pettijohn/KiotaIssue/blob/main/kiota-generate.sh |
Thanks for the additional context here. |
My guess is that they added this additional empty type because they either want to enable type assertion / matching to be used as logic control flow. Or because they anticipate additional properties for that derived type in the future. Or both. |
Would you be willing to look into the solution I have suggested and submit a pull request given some guidance? |
Can you give me a code pointer to get me started on changing the squashing logic? I can try to look at it this weekend. |
Great! The triage and merging logic is here. kiota/src/Kiota.Builder/KiotaBuilder.cs Line 1634 in 44d61a4
And the tests start here
Let us know if you have other questions |
Before I test this and submit a PR, can you please let me know if I'm doing about what you had in mind? In the switch statement you referenced in I'm not sure if I'm determining if it was referenced by oneOf in the right/clean/optimal way. I suspect there's a more elegant way to do that? Or maybe not and I should just add comments & tests. |
I think this is a good start. |
Appreciate the early feedback. I expect to have a busy week at work so it'll be a bit before I return to this. I'll make the changes you suggest and submit a PR for iterating. |
What are you generating using Kiota, clients or plugins?
API Client/SDK
In what context or format are you using Kiota?
Linux executable
Client library/SDK language
Csharp
Describe the bug
I am working with the Schwab API and their schema. I have published a repo to go along with this issue. https://github.com/pettijohn/KiotaIssue/
In the schema, there are a number of models that extend
AccountsBaseInstrument
using allOf.Most of these generated C# classes extend AccountsBaseInstrument, as expected (
AccountCashEquivalent, AccountFixedIncome, AccountOption, CollectiveInvestment
generate as expected). Two do not -AccountEquity, AccountMutualFund
. E.g.,Reviewing the documentation, I think this is actually by design. If I understand this correctly: https://learn.microsoft.com/en-us/openapi/kiota/models#components-versus-inline-models AccountEquity and AccountMutualFund fall into the rule "Class/interface with properties from the referenced schema and without a parent type."
That's a bummer, because there are instances where I only care about properties on the base type and I want to be able to treat them all the same:
To work around, I added an empty property to the classes to get it to generate inheriting from the base class.
Is there a better way? Or maybe this is a feature request - if other generated classes inherit from the base class, then so should all generated classes.
Expected behavior
Generated classes inherit from AccountsBaseInstrument
How to reproduce
See schema in initial commit and generate https://github.com/pettijohn/KiotaIssue/
Open API description file
No response
Kiota Version
1.16.0
Latest Kiota version known to work for scenario above?(Not required)
No response
Known Workarounds
No response
Configuration
Docker, WSL, Ubuntu 22.04, Windows 11
Debug output
Click to expand log
```The text was updated successfully, but these errors were encountered: