OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
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.
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.
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
andfull-repository
have a propertylicense
that points to the same subschema. Originally, thatlicense
schema had 2anyOf
elements, one istype = null
and the other isref = ...
.After the first normalization/simplification step for the
repository
schema, thelicense
schema is madenullable
and theanyOf
element withtype = null
is removed. Since there is only a singleanyOf
left, the code inOpenAPINormalizer#processSimplifyAnyOf
setsnullable = true
on the other anyOf withref = ...
, and returns that for thelicense
property of therepository
schema. By this time, the damage was already done, since thelicense
property schema offull-repository
now only has a singleanyOf
left which on top of all that is also markednullable = true
. When enteringOpenAPINormalizer#processSimplifyAnyOf
again for thelicense
property offull-repository
, theanyOf
is removed, becauseisNullTypeSchema
only checks if thenullable
flag is set. Since it was set by the previous normalization, the schema forlicense
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.
anyOf
schemas asnullable = true
, only the containing schemaschema.get$ref() == null
in the check inisNullTypeSchema