Hello,
If we've got a getter on a class that we don't want to include in the swagger output, is there currently any method to suppress/hide this?
So for example, there are two getters - getUser() and getUserId() - userId is returned in the rest response. GetUser currently returns an object|false, but won't be in the rest response.
That will currently fail as it returns two types with a "property defines more than one type" - are there any objects to suppress this when building the model from the class i.e. Model(type=user::class)
Thanks
If you're using jms serializer, you can use @Expose, if you're using the symfony serializer, you can use @Groups to filter serialized properties.
Thanks Guilhemn - i'll check over weekend whether that's what I've done and close
I guess it's solved, so I'm closing this, feel free to reopen if not.
Hi GuilhemN, Could you help me with an example?
Thanks
@ingedgarmorales you need to add composer require jms/serializer-bundle this bundle and then you can use the Exclude annotation in your Entity
@Serializer\Exclude()
I think I'm dreaming... ok, let me summarize what you considered above "a solution" xD
So, just to solve that problem, you're ready to use another vendor, a whole vendor (!!!!) jms/serializer-bundle, just for that tiny little problem ?
Plus, using the annotation @Expose or @Groups in your object may be a bad idea if you're trying to apply Domain Driven Design principles :
Your value object is part of the Domain, JMS annotations are part of the Infrastructure, and both must be separated.
From symfony 5.2 you can also use the @Ignore annotation from the sf serializer.
You may have a look at https://github.com/nelmio/NelmioApiDocBundle/issues/1595#issuecomment-652628318.
Or serializer config files, whatever you prefer.
The @Ignore annotation seems not to work in this configuration:
Symfony 5.2.1
NelmioApiDocBundle v4.1.1
...
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Security\Core\User\UserInterface;
...
class MyModelClass implements UserInterface
{
...
/**
* @var string Password
* @Ignore()
*/
private $password;
/**
* This function must be here because the class is a UserInterface
*/
public function getPassword():string
{
return $this->getToken();
}
}
Unfortunately, the 'password' string is displayed in the API documentation. Am I doing something wrong?
Thanks for your help!
Adrian
Most helpful comment
I think I'm dreaming... ok, let me summarize what you considered above "a solution" xD
So, just to solve that problem, you're ready to use another vendor, a whole vendor (!!!!)
jms/serializer-bundle, just for that tiny little problem ?