IBX-12046: Described OpenAPI responses with ApiPlatform\OpenApi\Model\Response objects - #245
Conversation
…\Response objects API Platform 4.2 calls Response methods (e.g. getDescription()) on every responses entry when building the OpenAPI document, so a plain array no longer works there. Converts every responses array entry across the REST controllers (and the OpenApiFactoryTest fixture) from a plain array to a new ApiPlatform\OpenApi\Model\Response instance, keeping the same description/content/headers values so the generated OpenAPI document is unchanged.
…s Response objects insertIbexaResponseExample() only handled plain-array responses, so with the responses now described as ApiPlatform\OpenApi\Model\Response objects the example files were no longer inlined. Response objects are updated with withContent(), which also keeps their headers; plain arrays (third-party bundles) keep working.
| '$ref' => '#/components/schemas/Session', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/sessions/POST/Session.xml.example', | ||
| Response::HTTP_OK => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description: here? Before this PR the key was missing, and OpenApiFactory used the status code 201 as the description. Now Model\Response defaults to an empty string, so the generated docs will show an empty description.
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| 'content' => [ | ||
| Response::HTTP_OK => new Model\Response( | ||
| description: 'If set, the list is returned in XML or JSON format.', | ||
| content: new \ArrayObject([ |
There was a problem hiding this comment.
Fixed in c5c1207. ArrayObject is now imported in every controller that uses it in the OpenAPI attributes.
| '$ref' => '#/components/schemas/UserGroupRefList', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/users/user_id/groups/POST/UserGroupRefList.xml.example', | ||
| Response::HTTP_OK => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| '$ref' => '#/components/schemas/User', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/users/user_id/PATCH/User.xml.example', | ||
| Response::HTTP_CREATED => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| '$ref' => '#/components/schemas/UserGroup', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/groups/path/subgroups/POST/UserGroup.xml.example', | ||
| Response::HTTP_CREATED => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| '$ref' => '#/components/schemas/UserGroupList', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/groups/GET/UserGroupList.xml.example', | ||
| Response::HTTP_OK => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| '$ref' => '#/components/schemas/UserGroupRefList', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/users/user_id/groups/POST/UserGroupRefList.xml.example', | ||
| Response::HTTP_OK => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
| '$ref' => '#/components/schemas/UserGroupRefList', | ||
| ], | ||
| 'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/user/users/user_id/groups/POST/UserGroupRefList.xml.example', | ||
| Response::HTTP_OK => new Model\Response(content: new \ArrayObject([ |
There was a problem hiding this comment.
Could we add a description?
There was a problem hiding this comment.
Fixed in 918666e. Added a description: in the wording of the sibling responses.
|



Related PRs:
$responsesPHPStan baseline entries.Description:
The REST controllers documented their OpenAPI responses as plain nested arrays in
openapi: new Model\Operation(responses: [...]). API Platform 4.2 — the release that replaces its XML service configuration, needed for Symfony 8 — callsResponsemethods on everyresponsesentry while building the document, so plain arrays fail withCall to a member function getDescription() on array; PHPStan also flags them (Operation::__construct()expectsarray<Response>|null).All 436 response entries in 140 controllers are now
Model\Responseobjects ('description'→description:,'content'/'headers'→new \ArrayObject([...])); status-code keys and the documented content are unchanged.Model\Responsehas the same constructor in API Platform 4.1, so this works before and after the bump.OpenApiFactory::insertIbexaResponseExample()inlinedx-ibexa-example-file(283 references in the controllers) only for plain-array responses, so it now also handlesModel\Responseobjects — updated withwithContent(), which additionally keeps their headers (the array path rebuilt the response without them). Plain arrays from third-party bundles keep working. New unit tests cover response objects with and without example files.For QA:
No functional change — same OpenAPI document, response examples included. PHP 8.3 and 8.4 on
6.0dependencies (API Platform 4.1): unit and integration suites exit 0, PHPStan and code style clean. With API Platform 4.2.26 installed temporarily: no$responsesPHPStan errors, and the full OpenAPI document (75 paths) builds from the integration kernel without errors.Documentation:
N/A