OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

AnyOf normalization/simplification isNullTypeSchema issue #19439

Open beikov opened 3 weeks ago

beikov commented 3 weeks ago

Bug Report Checklist

Description

When importing the schema for the GitHub API, wrong Java code is generated for FullRepository#license. While debugging, I figured that both schemas, repository and full-repository have a property license that points to the same subschema. Originally, that license schema had 2 anyOf elements, one is type = null and the other is ref = ....

After the first normalization/simplification step for the repository schema, the license schema is made nullable and the anyOf element with type = null is removed. Since there is only a single anyOf left, the code in OpenAPINormalizer#processSimplifyAnyOf sets nullable = true on the other anyOf with ref = ..., and returns that for the license property of the repository schema. By this time, the damage was already done, since the license property schema of full-repository now only has a single anyOf left which on top of all that is also marked nullable = true. When entering OpenAPINormalizer#processSimplifyAnyOf again for the license property of full-repository, the anyOf is removed, because isNullTypeSchema only checks if the nullable flag is set. Since it was set by the previous normalization, the schema for license is left with no possible types.

openapi-generator version

7.8.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/github/rest-api-description/raw/main/descriptions-next/api.github.com/api.github.com.json

Generation Details
Steps to reproduce

Just generate code with the jersey3 library and jackson serializationLibrary.

Related issues/PRs
Suggest a fix

There are multiple possible fixes, though I have not yet tried any of them.

beikov commented 3 weeks ago

3) Adding the condition seems to do the trick. Will do some further testing and provide a PR with a fix as soon as I fixed all the issues with importing the GitHub API.