Fix JSON:API collection included schema#8190
Conversation
| $collectionProperties = [ | ||
| 'data' => [ | ||
| 'type' => 'array', | ||
| 'items' => $properties['data'], | ||
| ], | ||
| ]; | ||
|
|
||
| if (isset($properties['included'])) { | ||
| $collectionProperties['included'] = $properties['included']; | ||
| } | ||
|
|
||
| $schema['description'] = "$definitionName collection."; | ||
| $schema['allOf'] = [ | ||
| ['$ref' => $prefix.(false === $operation->getPaginationEnabled() ? self::COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION : self::COLLECTION_BASE_SCHEMA_NAME)], | ||
| ['type' => 'object', 'properties' => [ | ||
| 'data' => [ | ||
| 'type' => 'array', | ||
| 'items' => $properties['data'], | ||
| ], | ||
| ]], | ||
| ['type' => 'object', 'properties' => $collectionProperties], |
There was a problem hiding this comment.
Could be simpler by mutating $properties['data'] in place instead of introducing a $collectionProperties intermediate. That way included (and any future top-level key returned by buildDefinitionPropertiesSchema) flows through automatically:
$properties['data'] = [
'type' => 'array',
'items' => $properties['data'],
];
$schema['description'] = "$definitionName collection.";
$schema['allOf'] = [
['$ref' => $prefix.(false === $operation->getPaginationEnabled() ? self::COLLECTION_BASE_SCHEMA_NAME_NO_PAGINATION : self::COLLECTION_BASE_SCHEMA_NAME)],
['type' => 'object', 'properties' => $properties],
];Removes the explicit isset($properties['included']) branch and keeps the wrapper shape consistent with the item schema.
| ], | ||
| ]; | ||
|
|
||
| if (isset($properties['included'])) { |
There was a problem hiding this comment.
Nit: buildDefinitionPropertiesSchema returns 'included' => [...] only when relationships exist (see L357-376), so it can never be null here — isset() is safe. If the suggestion above is applied this branch goes away anyway.
|
Addressed the review suggestion in the latest commit ( Validation was run in an ephemeral Composer/PHP container:
|
f37dde8 to
55a4e41
Compare
55a4e41 to
96f8b80
Compare
|
I rebased the branch on the current main and squashed the PR changes into a conventional commit (ix(jsonapi): include collection schema data properties) so commitlint should pass now. I also re-ran the relevant functional coverage locally in a Composer/PHP container:
The previous Doctrine/Laravel failures were coming from new main changes ( |
96f8b80 to
3d988bb
Compare
|
Reworked the branch onto the correct Local validation passed in an isolated container: vendor/bin/phpunit tests/Functional/OpenApiTest.php --filter testJsonApiCollectionSchemaDocumentsIncludedResources
vendor/bin/phpunit tests/Functional/OpenApiTest.phpResults: focused test OK with 1 test / 6 assertions; full |
|
The branch is now on the correct 4.3 base and the refreshed CI run is green. Please let me know if anything else is needed from my side. |
Fixes #7956.
Preserves the JSON:API included schema when building OpenAPI schemas for collection responses and adds a functional regression test.
Tests: