Skip to content
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

Kiota produces different model with same command and OpenAPI description #4139

Closed
bmarkovic17 opened this issue Feb 6, 2024 · 5 comments
Closed
Assignees
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close

Comments

@bmarkovic17
Copy link

I also ran into the issue with Kiota not being idempotent and after going through the already existing issues (mainly #2442) I decided to create a new one as it might provide more insight. The problem basically boils down to these few classes shown on image below where most of them don't get generated, while the one that depends on them gets generated differently.

image

Setting the environment variable KIOTA_GENERATION_MAXDEGREEOFPARALLELISM to 1 didn't help, but I've noticed something that might be helpful:

  • generate command will almost everytime produce a wrong model
    • I have an impression that the model gets generated okay when the command takes a bit longer to execute (around 10s), while usually it takes around 5s and then it gets it wrong. This is my feeling that could be wrong
  • update command will almost everytime produce a correct model
    • on one occassion it produced a TeamAndCompetitor class in the same way that the generate command produces it, even though the othere classes were not missing

Here is the the OpenApi description that I'm using with Kiota 1.11.1 and here are the commands that I've used to generate the client:

  • kiota generate --openapi openapi.json --language csharp --clean-output --clear-cache --exclude-backward-compatible
  • kiota update

Let me know if you need more information or I can help in any way.

Thanks.

@bmarkovic17
Copy link
Author

EDIT: After further analysis I've noticed that the issue is actually related to the --clean-output parameter as kiota update --clean-output also started generating wrong models. When I remove the parameter, model generation mostly works okay, but from time to time fails regardless.

Here is an example with a faulty model even though the --clean-output parameter was not present.

image

@baywet baywet added enhancement New feature or request help wanted Issue caused by core project dependency modules or library generator Issues or improvements relater to generation capabilities. Needs: Author Feedback labels Feb 6, 2024
@baywet baywet added this to the Backlog milestone Feb 6, 2024
@baywet
Copy link
Member

baywet commented Feb 6, 2024

Hi @bmarkovic17
Thanks for using kiota and for reaching out.
I'm pretty sure this has nothing to do with which command or argument you pass in but rather because of this in the description:

"TeamAndCompetitor": {
				"allOf": [
					{
						"$ref": "#/components/schemas/Competitor"
					},
					{
						"$ref": "#/components/schemas/Team"
					}
				]
			},

Long story short, kiota implements the following rules for the schema elements:

kind scenario result
allOf single entry not meaningful, will flatten the and use the single entry
allOf one inline entry, one reference entry inheritance
allOf multiple inline, or multiple reference entries not really implemented, it should probably deterministically elect one reference as the parent and fall back to an inheritance case
oneOf single entry not meaningful, will flatten the and use the single entry
oneOf no/single/multiple inline entries and/or no/single/multiple reference entries will generate inline types for the inline schemas, will generate an exclusive union type
anyOf single entry not meaningful, will flatten the and use the single entry
anyOf no/single/multiple inline entries and/or no/single/multiple reference entries will generate inline types for the inline schemas, will generate an inclusive union type

The main logic behind all of this is here

private CodeTypeBase? CreateModelDeclarations(OpenApiUrlTreeNode currentNode, OpenApiSchema schema, OpenApiOperation? operation, CodeElement parentElement, string suffixForInlineSchema, OpenApiResponse? response = default, string typeNameForInlineSchema = "", bool isRequestBody = false)

And you can duplicate and tweak this unit test

public void UnionOfInlineSchemasWorks()

With that context in mind, is this something you'd be willing to work on a pull request for?

@bmarkovic17
Copy link
Author

Thanks for the clarification @baywet.
I can't commit any serious time at the moment but I'll look into it during the weekends.

@baywet
Copy link
Member

baywet commented May 17, 2024

@bmarkovic17 can you test this again with the latest preview from yesterday and confirm whether you observe the problem? We've made significant improvements to the handling of allof edge scenarios with #4668 and #4381

@baywet baywet added status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close and removed Needs: Attention 👋 labels May 17, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed this from the Backlog milestone May 24, 2024
@github-project-automation github-project-automation bot moved this from Todo 📃 to Done ✔️ in Kiota May 24, 2024
@bmarkovic17
Copy link
Author

@baywet Sorry for my late reply, we were busy with some other stuff that had a narrow deadline.
Today I found some time to test this again and I'm happy to say that with kiota v1.15.0 I couldn't reproduce it. The generated model was always the same, regardless how I run kiota.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generator Issues or improvements relater to generation capabilities. help wanted Issue caused by core project dependency modules or library status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close
Projects
Archived in project
Development

No branches or pull requests

2 participants