[php-nextgen] oneof polymorphism
Merged
CO
5mo ago+4665+4665+0123456789012345678901234567890123456789-187-187-012345678901234567890123456789
- Javas
collectOneOfTypeHintbuilds a oneOf-classnameA|Bunion map. Applied to property, parameter, and return type hints. - A makeNullable helper emits
A|B|nullinstead of?A|B. model.mustachebranches tomodel_oneofwhenoneOfis present (otherwisemodel_generic).- new
model_oneof.mustache: implementingOneOfInterface OneOfInterface: marks modelsObjectSerializer:deserialize()detectsOneOfInterfaceand uses the interfacesdeserializeOneOf
non-discriminated members with no required fields match greedily, so ambiguous data resolves to the first member.
Testing
- Added Apple, Banana, Fruit without discriminator
- Added Whale, Zebra, Mamal with discrimnator
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.
Summary by cubic
Adds oneOf polymorphism to the PHP NextGen generator. Models generated from oneOf act as typed unions at runtime and in signatures/PHPDoc, including properties and arrays.
-
New Features
- Added
OneOfInterfaceandmodel_oneof.mustache;model.mustacheroutesoneOfschemas to it. ObjectSerializerdetectsOneOfInterfaceand resolves to the right member via discriminator or first matching member.PhpNextgenClientCodegenbuilds union maps and emitsA|BandA|B|nullin signatures; PHPDoc mirrors signatures viaexts.x-php-prop-doc-typeandexts.x-php-param-doc-type.- API
*WithHttpInfoPHPDoc now uses precise array-shape types (e.g.,array{0: T, 1: int, 2: array<string, string[]>}). - Model docs for
oneOfwrappers list member types and, when present, the discriminator property; generator docs now mark polymorphism as supported. - Samples include
Zooand petstore/fake/oneof. - Improved and linked Javadocs.
- Added
-
Migration
- Regenerate clients to pick up
oneOfsupport. - Ambiguous non‑discriminated members with no required fields resolve to the first member.
- Nullable unions are
A|B|null(never?A|B), and|nullis added only when a success response can be empty (e.g., 204); empty error responses do not affect return types.
- Regenerate clients to pick up