Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with extending {XML,Yaml} -> {XML,Yaml} resources #5956

Open
wants to merge 2 commits into
base: 3.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Metadata/Extractor/YamlResourceExtractor.php
Expand Up @@ -75,14 +75,15 @@ private function buildResources(array $resourcesYaml, string $path): void
$resourceYaml = [$resourceYaml];
}

$resourcesCount = isset($this->resources[$resourceName]) ? \count($this->resources[$resourceName]) : 0;
foreach ($resourceYaml as $key => $resourceYamlDatum) {
Copy link
Member

Choose a reason for hiding this comment

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

is key always an int @vincentchalamon ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm not sure that it's always an int, cf. https://github.com/api-platform/core/blob/main/src/Metadata/Tests/Extractor/yaml/valid.yaml

To be sure, it would be better to rely on an int variable declared out of this foreach and incremented accordingly.

if (null === $resourceYamlDatum) {
$resourceYamlDatum = [];
}

try {
$base = $this->buildExtendedBase($resourceYamlDatum);
$this->resources[$resourceName][$key] = array_merge($base, [
$this->resources[$resourceName][$resourcesCount + $key] = array_merge($base, [
'operations' => $this->buildOperations($resourceYamlDatum, $base),
'graphQlOperations' => $this->buildGraphQlOperations($resourceYamlDatum, $base),
]);
Expand Down
Expand Up @@ -60,7 +60,7 @@ public function create(string $resourceClass): ResourceMetadataCollection
}
}

$resourceMetadataCollection[$i] = $resource;
$resourceMetadataCollection[] = $resource;
}

return $resourceMetadataCollection;
Expand Down