Trying to figure out the right way to use this so I suspect this is another operator-error but don't know where to look for examples or guidance.
I have a FOSRest controller with typical actions for dealing with my User entity. I annotated my getAction() method as show below. I've not added any SWG annotations to the entity. I'm getting an error indicating The PropertyInfo component was not able to guess the type of AppBundle\\Entity\\User::$displayName. My User entity doesn't have a $displayName property. It has a getDisplayName() method that returns a string based on the $username, $firstname, and $lastname properties which do exist.
Is it a mistake that the bundle thinks there should be a $displayName propery? Or, do I need to annotate the getDisplayName() method somehow to avoid this?
/**
* Get one user.
*
* @Operation(
* tags={"Users"},
* summary="Get one user",
* @SWG\Parameter(
* name="user",
* in="path",
* description="ID or username",
* required=true,
* type="string"
* ),
* @SWG\Response(
* response="200",
* description="HTTP OK",
* @Model(type=User::class)
* ),
* @SWG\Response(
* response="401",
* description="HTTP UNAUTHORIZED"
* ),
* @SWG\Response(
* response="403",
* description="HTTP FORBIDDEN"
* ),
* @SWG\Response(
* response="404",
* description="HTTP NOT FOUND"
* )
* )
*/
public function getAction(User $user)
{
$this->denyAccessUnlessGranted('VIEW', $user);
return $user;
}
The PropertyInfo component does indeed detect getters. If you're using the symfony serializer I guess you can use groups to remove this field.
Otherwise you can still manually define a schema in your config.
I'm using JMSSerializer and tried adding @JMS\Exclude to the getDisplayName() method but I'm still getting the error.
Yeah, jms metadata aren't supported yet... I have to work on it :)
Could you point me toward an example of using groups?
Delved into the the PropertyInfo Extractors and found that if I rename getFoo() to foo() it doesn't show up in the getProperties() results.
See https://github.com/nelmio/NelmioApiDocBundle/pull/1024 for jms support.
Could you point me toward an example of using groups?
I don't think it will fit your case as you're not using the symfony serializer, the best would be to merge https://github.com/nelmio/NelmioApiDocBundle/pull/1024 but I need some help to write tests...
I've been running into this quite a bit with the following error
The PropertyInfo component was not able to guess the type of DateTime::$timezone
This happens when you attempt to define a field which takes a DateTime, because it can't introspect that it should be
{
"type": "string",
"format": "date-time",
}
So instead it attempts to serialize the entire DateTime object, which doesn't have a $timezone property but does have getters and setters for it.
Same here when I try to put my model in my input parameter :
/**
* ...
* @SWG\Parameter(
* name="body",
* in="body",
* @SWG\Schema(
* type="array",
* @Model(type=Connection::class)
* )
* ),
*/
I get this message :
The PropertyInfo component was not able to guess the type of Doctrine\Common\Collections\Collection::$element
And I return Doctrine Collection like that :
/**
* Get variants
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getVariants()
{
return $this->variants;
}
@davidbonachera I was able to reproduce your issue, the problem is that Doctrine\Common\Collections\Collection is considered as an object instead of a collection. This should be fixed by https://github.com/nelmio/NelmioApiDocBundle/pull/1050.
I constantly get this error in my entities, it's asking me to better define $id, in a class that lacks ID (as the PK has a different name), any idea ?
using groups worked for me
```php
// Controller
class FooAction
// Payload
use Symfony\Component\Serializer\Annotation\Groups;
class Payload
{
/**
// throw error
public function getFoo() {}
}
Most helpful comment
Yeah, jms metadata aren't supported yet... I have to work on it :)