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: passing class as parameter in XML ApiResource's definition #6659

Merged

Conversation

GSadee
Copy link
Contributor

@GSadee GSadee commented Sep 23, 2024

Q A
Branch? 3.4
Tickets
License MIT
Doc PR

In Sylius, where we use API Platform, it is important for us to be able to extend entities and because of this we would like to pass the class as a parameter, which is not possible at the moment due to an error:

request.CRITICAL: Exception thrown when handling an exception (Symfony\Component\Config\Exception\LoaderLoadException: The class or interface "%sylius.model.taxon.class%" does not exist in

This happens because in the XmlResourceExtractor, the key class is set in the ApiResource metadata with a value that does not point to a specific class, but is a parameter key. This is not done in the YamlResourceExtractor, so in order to make the both extractors consistent with each other, I remove the setting of this wrong value. An alternative would be to set the already resolved class via the resolve metadata, but I don't think this is needed because the corresponding class is set as a key in the resources array.

@GSadee GSadee force-pushed the fix-remove-setting-class-in-xml-extractor branch from 88c8659 to 2ff4527 Compare September 23, 2024 05:37
Wojdylak added a commit to Sylius/Sylius that referenced this pull request Sep 23, 2024
…nfigs (#16992)

| Q               | A
|-----------------|-----
| Branch?         | 2.0
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations? | no<!-- don't forget to update the UPGRADE-*.md file
-->
| Related tickets | api-platform/core#6659
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.13 branch
 - Features and deprecations must be submitted against the 1.14 branch
- Features, removing deprecations and BC breaks must be submitted
against the 2.0 branch
 - Make sure that the correct base branch is set

To be sure you are not breaking any Backward Compatibilities, check the
documentation:

https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->
@@ -61,7 +61,6 @@ protected function extractPath(string $path): void
foreach ($xml->resource as $resource) {
$base = $this->buildExtendedBase($resource);
$this->resources[$this->resolve((string) $resource['class'])][] = array_merge($base, [
'class' => $this->phpize($resource, 'class', 'string'),
Copy link
Member

Choose a reason for hiding this comment

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

would it be possible to resolve instead in both extractors? A resource without a class is definitely not valid to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about this, but in ApiResource the class field does not exist at all if it is not specified here, as far as I have seen, and at the same time the relevant class is indicated as the key, so setting the class here is a kind of unnecessary duplication

@soyuka soyuka merged commit afe7d47 into api-platform:3.4 Oct 4, 2024
77 of 78 checks passed
@soyuka
Copy link
Member

soyuka commented Oct 4, 2024

thanks!

@GSadee GSadee deleted the fix-remove-setting-class-in-xml-extractor branch October 4, 2024 09:43
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.

2 participants