Nullable "anyOf" type support #1674
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation of this change
Nullable types in json schema often represented as
"field":{ "anyOf":[{"type": "<real_type>"},{"type": "null"}]
which falls under union type handling and then typeObject
would be generated loosing the actual type information from the schema. I think there is a possibility to do more on this front as from type generation perspective nullability is only a matter of type boxing. This PR is to address / recognise this exact scenario and use the type information from the union while leave other union type scenarios unchanged.Changes
resolveNullableType
method to top levelSchemaRule
to detect exactly this scenario and use boxed typeEdge case: when such a field is required then we should not add a
NonNull
/NotNull
annotations since the field is nullable by default. To handle that I changed passing the property schema in type rules instead of the parent. It was only used at NotRequiredRule.java but there I could use parent instead.The rest of the changes are testing related and some minor improvements. Any feedback is welcome!