-
Notifications
You must be signed in to change notification settings - Fork 214
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
Relations between inheritance trees breaks code generation #2781
Comments
This is described in microsoft#2781
Thanks for submitting PR #2782 (and the other one before). I've been a bit overloaded after coming back from a long leave, but I'll take a look at both as soon as I can. |
No problem. I think Kiota does a much better job at generating code from an OpenAPI spec than what I've seen from other projects. This one is just an unfortunate bug. With Kiota, we finally see a route to delivering high quality generated SDKs for our API. |
I've done some debugging, and I think I may have found the location of the problem. In |
The |
Thank you for looking into this further and sharing your progress. Effectively we're flattening some schemas because they don't hold meaning. They are usually the result of a bad generation from certain services. Or they only carry some description, nullable information, etc... At the time we implemented that, the rules about which property to consider and which to ignore were not clearly defined and this was done in an exploratory way. But we have an issue to address the consistency aspect in the near future. #2434 If you have additional questions to get further context don't hesitate. |
Given a type hierarchy with 3 levels, the base class has a single schema. The intermediate class has a schema with an allOf with 2 parts (reference to super class and it's own properties). The subclass also has a schema with an allOf with 2 parts. This looks like this:
The For now, I've managed to find a workaround for this issue by giving the subschemas with the properties (IntermediateProps and SubClassProps) a title with the name of the type they belong to. This hints Kiota into selecting the correct class name. It's not clear though why this title attribute is used for this, as the JSON Schema specification seems to suggest the title is meant to be human readable. |
Thanks for digging further. This is effectively what #2434 is meant to address. |
Well, yes and no. At the moment I actually use the behavior described in #2434 to work around the issue with the name generation. So if that ticket is fixed, generation will be broken again for our spec. I do agree that Kiota should not use the title to generate a name, but it should generate predictable names in some way. In #2745 I proposed a solution for that specific issue: preprocessing of the OpenAPI spec. That might work for this issue as well. Suppose you add a new step in the generator that takes the OpenAPI spec as it is read from file and produces a normalized and annotated OpenAPI spec. This step could merge Unfortunately, being mainly a Java developer, my knowledge of C# is limited and our schedule at the moment does not give me the room to both learn a new language and work on such an enhancement. |
Let's explore this pre-processing step further. Besides normalizing the JSON schemas, what else would it do? Would you expose it as a separate command to users? |
It could perform a lot of the name resolution and conversion that is now part of the code generation. The results of this could be stored in dedicated extension properties in the resulting OpenAPI. This could, for example solve many of the concerns raised in #2498. It would also solve another issue we are facing at the moment, where a
These new properties I would also expose this as a standalone command. The output will serve several different purposes. It allows users to see how Kiota interprets the OpenAPI spec. It can be used to normalize a spec (perhaps with the option to drop the x-kiota-* properties). It can be used to troubleshoot Kiota itself. And, it will also serve as a living documentation of the supported x-kiota-* properties. |
Thanks for the additional context. This is an interesting suggestion. We've never had a pre-processing step in mind (besides maybe what OpenAPI.net and associated validation rules do) throughout the history of this project. More often than not, description quality/accuracy gets in the way of the generation work. Having a pre-processing step to remove the noise might be beneficial. I'm a bit worried about the refactoring cost at this point. |
This is described in microsoft#2781
This is described in microsoft#2781
While trying to generate code for our project, I noticed some types got pruned which shouldn't have been pruned. Closer investigation showed that the inheritance chain for some of the types is broken. I've managed to produce a minimal testcase, which I will submit as a PR against current
main
. In the spec in this PR, you will see some types that are not used, but that's only because I removed the operations referencing those types. The operations were not needed to reproduce the issue, but the types were. The issue is present in at least C#, Go and Java, so it seems unrelated to the target language.The result of the code generation should have been an inheritance chain with
Linkable
>GroupClassificationPrimer
>GroupClassification
. However, the primer class is missing, and strangely, theGroupClassification
has the properties of the primer, not its own properties. In this example, this results in aGroupClassification
extendingLinkable
and with only aname
, not thedescription
. All the other parts in the spec seem to be needed to reproduce this issue. For example, when you remove the propertymarkers
fromGroupPrimer
, which referencesItemMarkers
, the code is generated correctly. Both these types have nothing to do withGroupClassification
, but still seem to influence its generation.The text was updated successfully, but these errors were encountered: