[php-nextgen] Fix Nested `oneOf`/`anyOf` Behavior

Merged
CK
4mo ago
+348-21

This PR builds off of work done in #24306. It flattens composed union type-hints transitively so a nested composed property resolves to its leaf members. Previously, composed property type-hints only listed their direct members, so when a composed type nested another composed type, the deserializer returned a leaf instance the property's union rejected and threw a TypeError.

Once #24306 is merged, I'll update this and mark as ready for review.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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 proper anyOf support and fixes nested oneOf/anyOf in php-nextgen by flattening composed unions to their leaf types. Model docs now list and link the leaf types to match generated method signatures.

  • Bug Fixes

    • Split composed handling into OneOfInterface and AnyOfInterface; ObjectSerializer dispatches via deserializeOneOf/deserializeAnyOf after json_decode, preserves raw strings on decode failure, and improves discriminator/array resolution.
    • Flatten nested union type-hints transitively for models and operations with a cycle-safe pass (collapse arrays/maps to array, keep original hints for fully cyclic graphs); expose leaves via x-php-composed-leaves and render them in model_doc.mustache. Samples and tests cover nested cases (e.g., Creature โ†’ Whale|Zebra|Lizard|Snake; Zoo.featuredCreature uses the leaf union), and avoid emitting invalid PHP types.
  • Migration

    • No change to OneOfInterface; AnyOfInterface is new. Regenerate clients.