[PHP] Add support to nullable (based on #3493) #12794
Merged
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.
This is basically PR #3493, rebased, adjusted to the latest code and with some bug fixes and code modernization. @githubERIK, the author of the original PR, said he doesn't plan to continue with that (#3493 (comment)), but we have been using his code in our fork for more than 2 years, with no issues! 😄
His biggest concert was support for openapi 2.0. But this is not a problem at all: OpenAPIGenerator is setting
isNullable
to true if'x-nullable'
is defined in the swagger file, which means, this code works OOTB with openapi 2.0, provided thatx-nullable
is properly set.The most important changes to the original code are:
isNullable()
: changed to useself::openAPINullables()
method instead of the property itself. This is a bugfix: if we don't do this, parent properties will not be checked.getOpenAPINullablesSetToNull()
andsetIfExists()
: changed to private, since they are internal to the model class.openAPINullables()
: changed to protected, since it is only used within class and parent scope.setIfExists()
: changed to return void, as it is used only internally and its return is never used.isNullable()
andisNullableSetToNull()
to ModelInterface.mustache, which didn't exist when the original PR was presentedIf the original author prefers, I can present these changes as a patch to his own PR, or he can add me to his branch so that I can merge them myself. The only important thing for me is to see the feature in OpenAPIGenerator base code, as a) it works very well! 😄 and b) this would help us moving away from using a fork 😉
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.1.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)@jebentier, @dkarlovi, @mandrean, @jfastnacht, @ybelenko, @renepardon