[php-nextgen] oneof polymorphism

Merged
CO
5mo ago
+4665-187
  • Javas collectOneOfTypeHint builds a oneOf-classname A|B union map. Applied to property, parameter, and return type hints.
  • A makeNullable helper emits A|B|null instead of ?A|B.
  • model.mustache branches to model_oneof when oneOf is present (otherwise model_generic).
  • new model_oneof.mustache: implementing OneOfInterface
  • OneOfInterface: marks models
  • ObjectSerializer: deserialize() detects OneOfInterface and uses the interfaces deserializeOneOf

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:
    ./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.

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 OneOfInterface and model_oneof.mustache; model.mustache routes oneOf schemas to it.
    • ObjectSerializer detects OneOfInterface and resolves to the right member via discriminator or first matching member.
    • PhpNextgenClientCodegen builds union maps and emits A|B and A|B|null in signatures; PHPDoc mirrors signatures via exts.x-php-prop-doc-type and exts.x-php-param-doc-type.
    • API *WithHttpInfo PHPDoc now uses precise array-shape types (e.g., array{0: T, 1: int, 2: array<string, string[]>}).
    • Model docs for oneOf wrappers list member types and, when present, the discriminator property; generator docs now mark polymorphism as supported.
    • Samples include Zoo and petstore /fake/oneof.
    • Improved and linked Javadocs.
  • Migration

    • Regenerate clients to pick up oneOf support.
    • Ambiguous non‑discriminated members with no required fields resolve to the first member.
    • Nullable unions are A|B|null (never ?A|B), and |null is added only when a success response can be empty (e.g., 204); empty error responses do not affect return types.