Skip to content

IBX-12046: Described OpenAPI responses with ApiPlatform\OpenApi\Model\Response objects - #245

Merged
ViniTou merged 4 commits into
6.0from
IBX-12046-openapi-response-objects
Sep 25, 2026
Merged

ViniTou merged 4 commits into
6.0from
IBX-12046-openapi-response-objects

Conversation

@ViniTou

@ViniTou ViniTou commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
🎫 Issue IBX-12046

Related PRs:

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 — calls Response methods on every responses entry while building the document, so plain arrays fail with Call to a member function getDescription() on array; PHPStan also flags them (Operation::__construct() expects array<Response>|null).

All 436 response entries in 140 controllers are now Model\Response objects ('description' → description:, 'content' / 'headers' → new \ArrayObject([...])); status-code keys and the documented content are unchanged. Model\Response has the same constructor in API Platform 4.1, so this works before and after the bump.

OpenApiFactory::insertIbexaResponseExample() inlined x-ibexa-example-file (283 references in the controllers) only for plain-array responses, so it now also handles Model\Response objects — updated with withContent(), 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.0 dependencies (API Platform 4.1): unit and integration suites exit 0, PHPStan and code style clean. With API Platform 4.2.26 installed temporarily: no $responses PHPStan errors, and the full OpenAPI document (75 paths) builds from the integration kernel without errors.

Documentation:

N/A

…\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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing imports

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 918666e. Added a description: in the wording of the sibling responses.

@sonarqubecloud

Copy link
Copy Markdown

@ViniTou
ViniTou merged commit db1b5e0 into 6.0 Sep 25, 2026
9 checks passed
@ViniTou
ViniTou deleted the IBX-12046-openapi-response-objects branch September 25, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants