[php] Keep the model namespace for allOf-wrapped array items and parameters

YA
2h ago
+662-1

fix #25354

AbstractPhpCodegen.toAllOfName() returns the fully qualified type declaration of each allOf member. For an inline allOf with a single $ref (an array item or a parameter schema; properties are unwrapped earlier by DefaultCodegen.fromProperty()), that qualified name is what getSchemaType() receives, and toModelName() then strips the namespace separators, so php and php-nextgen emit types like \AcmeClientModelError[] and ?\AcmeClientModelSortDir that reference classes that do not exist.

This change mirrors the existing property handling:

  • toAllOfName(): with a single member, defer to the default implementation so a bare schema name comes back and baseType/complexType match the plain $ref case.
  • getTypeDeclaration(Schema): resolve a single-member allOf to its member's declaration, which the existing $ref branch qualifies with the model package.

Multi-member allOf (the A&B intersection form) is unchanged.

Tests

  • New PhpModelTest::complexListPropertyWithAllOfItems, which fails on master with expected [\OpenAPI\Client\Model\Children[]] but found [\OpenAPIClientModelChildren[]].
  • PhpModelTest, AbstractPhpCodegenTest, PhpClientCodegenTest, PhpNextgenClientCodegenTest: 57 tests, 0 failures.
  • The minimal spec from the issue now generates '\Acme\Client\Model\Error[]' and ?\Acme\Client\Model\SortDir for both generators.
  • A large real-world spec (14.8k lines, 316 models, 306 affected references) generated with this change is byte-identical to 7.26.0 output with the separators restored by post-processing, so there are no side effects beyond the mangled names.

Second commit: the issue's spec is now a fixture (src/test/resources/bugs/issue_25354.yaml) with a generation-level test in both PhpClientCodegenTest and PhpNextgenClientCodegenTest asserting the model type map and the API parameter, and the php-nextgen petstore sample spec gains an AllOfRefArray model so the regenerated samples/client/petstore/php-nextgen shows the fix ('tags' => '\OpenAPI\Client\Model\Tag[]') and the php-nextgen phpstan job exercises it. All 15 bin/configs/php* samples regenerated; only that sample changed.
PHP technical committee: @jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon

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.

šŸ¤– Generated with Claude Code


Summary by cubic

Fixes #25354 (PHP): single-member allOf schemas that wrap a $ref — such as array items and parameters — now generate correctly namespaced model names. Previously they produced mangled types like \AcmeClientModelError[] because toAllOfName() returned a fully qualified name that getSchemaType() stripped of namespace separators. Multi-member allOf (the A&B intersection form) is unchanged.

Bug Fixes

  • toAllOfName() returns the member's plain schema name for single members, so x-all-of-name is ignored consistently with getTypeDeclaration().
  • getTypeDeclaration(Schema) resolves a single-member allOf to the member's declaration so the $ref branch applies the model package.
  • Adds complexListPropertyWithAllOfItems to PhpModelTest, generation-level tests in PhpClientCodegenTest/PhpNextgenClientCodegenTest using a new issue_25354.yaml fixture, and an AllOfRefArray model in the php-nextgen petstore sample.
  • Leaves the sample's AllOfRefArrayTest.php out of the generated FILES manifest since test files are generated once and skipped when they exist.