[php] Keep the model namespace for allOf-wrapped array items and parameters
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 andbaseType/complexTypematch the plain$refcase.getTypeDeclaration(Schema): resolve a single-memberallOfto its member's declaration, which the existing$refbranch qualifies with the model package.
Multi-member allOf (the A&B intersection form) is unchanged.
Tests
- New
PhpModelTest::complexListPropertyWithAllOfItems, which fails on master withexpected [\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\SortDirfor 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:
(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.
š¤ 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, sox-all-of-nameis ignored consistently withgetTypeDeclaration().getTypeDeclaration(Schema)resolves a single-memberallOfto the member's declaration so the$refbranch applies the model package.- Adds
complexListPropertyWithAllOfItemstoPhpModelTest, generation-level tests inPhpClientCodegenTest/PhpNextgenClientCodegenTestusing a newissue_25354.yamlfixture, and anAllOfRefArraymodel in the php-nextgen petstore sample. - Leaves the sample's
AllOfRefArrayTest.phpout of the generatedFILESmanifest since test files are generated once and skipped when they exist.