Core: There is no PropertyInfo extractor supporting the class

Created on 13 Mar 2020  路  11Comments  路  Source: api-platform/core

API Platform version(s) affected: v2.5.4

Description
I try to implementing a custom operation (without specifying an ID). My situation:

Request: {"foo":"1"}
Response: {"bar":"2"}

I have Post request.

  • foo - it`s a first field in my php-object named MyObject
  • bar - it`s a second field in my php-object named MyObject

I try to solve my problem as it is written in the https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation

But, I have problem:

image

How to reproduce
https://github.com/yapro/api-platform-test/commit/bc70662c4f06b7769b781114d1d09031e47bb18f

Most helpful comment

I am using a resource class and using some value objects which only contain private properties and are not resources.

Uncaught PHP Exception ApiPlatform\Core\Exception\RuntimeException: "There is no PropertyInfo extractor supporting the class "App\Domain\Value\Tagdefinition\TagdefinitionUuid"." at /app/vendor/api-platform/core/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyNameCollectionFactory.php line 46

I can confirm that adding a dummy public $foo; property to the object fixes the error.

As PropertyNameCollection can handle an empty array, why not pass this instead of raising an exception?
https://github.com/api-platform/core/blob/f8ccee08710d442f0333530e96b835620947aa82/src/Metadata/Property/PropertyNameCollection.php#L31-L34

in

https://github.com/api-platform/core/blob/f8ccee08710d442f0333530e96b835620947aa82/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyNameCollectionFactory.php#L42-L50

I am not able to say sth. about the side effects or why this code behaves like this, but I am open to provide a PR if you agree @dunglas @teohhanhui

Cheers

EDIT
It was introduces 4 years ago by @dunglas in Fix some Scrutinizer issues

cc @localheinz

All 11 comments

AnalyticalReportResource has no properties?

@soyuka yes, like you see, all properties in AnalyticalReportInput and AnalyticalReportOutput objects.

Nope it's not working like this.

@soyuka so the documentation is outdated?

Having an input and an output never creates properties on a class.

@soyuka like you see, I don't wont to create the AnalyticalReportResource, but api-platform doesn't work without a third class (resource class), am I right?

Indeed, you need a resource class. You can also use symfony to declare a custom route without using our concepts.

Actually, to me this is a bug. Currently the PropertyInfoPropertyNameCollectionFactory throws an exception when it can't determine any properties. However, that should be considered perfectly normal, if a resource class does not have properties, or does not have properties which can be found by the PropertyInfo component, as other decorator factories can still fill that in.

I've come across this while working on other issues, and I'm not sure what's the rationale behind this.

/cc @dunglas if you remember why...

I am using a resource class and using some value objects which only contain private properties and are not resources.

Uncaught PHP Exception ApiPlatform\Core\Exception\RuntimeException: "There is no PropertyInfo extractor supporting the class "App\Domain\Value\Tagdefinition\TagdefinitionUuid"." at /app/vendor/api-platform/core/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyNameCollectionFactory.php line 46

I can confirm that adding a dummy public $foo; property to the object fixes the error.

As PropertyNameCollection can handle an empty array, why not pass this instead of raising an exception?
https://github.com/api-platform/core/blob/f8ccee08710d442f0333530e96b835620947aa82/src/Metadata/Property/PropertyNameCollection.php#L31-L34

in

https://github.com/api-platform/core/blob/f8ccee08710d442f0333530e96b835620947aa82/src/Bridge/Symfony/PropertyInfo/Metadata/Property/PropertyInfoPropertyNameCollectionFactory.php#L42-L50

I am not able to say sth. about the side effects or why this code behaves like this, but I am open to provide a PR if you agree @dunglas @teohhanhui

Cheers

EDIT
It was introduces 4 years ago by @dunglas in Fix some Scrutinizer issues

cc @localheinz

TBH I don't remember the rationale (if any...). If tests pass, it should be safe to change this behavior!

Thanks for your feedback!

Was this page helpful?
0 / 5 - 0 ratings