[php-nextgen] Add anyof Support
Merged
CK
4mo ago+2452+2452+0123456789012345678901234567890123456789-170-170-012345678901234567890123456789
Follow up to #23985
This PR adds support for anyOf models with and without discriminators. It copies the implementation from the oneOf model and updates some of the naming/logic to refer to Composed instead of oneOf or anyOf specifically.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
Commit all changed files.
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*.
IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
@jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12)
Summary by cubic
Adds anyOf support to the PHP Nextgen generator by introducing AnyOfInterface and generated dispatcher models, and updates ObjectSerializer to reliably dispatch oneOf/anyOf with safer JSON decoding. Samples, docs, and tests are regenerated, including new petstore anyOf models.
-
New Features
- Generate
anyOfdispatcher models viamodel_anyof.mustache; addAnyOfInterfaceand register it inPhpNextgenClientCodegen. - Add
deserializeAnyOf()and dispatch for bothOneOfInterfaceandAnyOfInterfaceinObjectSerializer; dispatch runs afterjson_decodeand before array-to-object casting. - Update model docs to list
anyOfmembers and discriminator selection; skip per-property test stubs for composed models; add petstoreReptile,Smoothie,Lizard,Snake; regenerate echo and petstore samples; addanyOfpolymorphism tests.
- Generate
-
Bug Fixes
- Preserve original strings when JSON decode fails (including the
"null"literal); catchThrowableduring deserialization; tighten composed-type validation.
- Preserve original strings when JSON decode fails (including the