Hi, I'm trying to move to 3.0, but when I use Model annotation, swagger-ui just prints empty object {}
/**
* Get conversation list
*
* @SWG\Get(
* @SWG\Response(
* response = Response::HTTP_OK,
* description="success",
* @SWG\Schema(
* type="object",
* @Model(type=ConversationRepresentation::class)
* ),
* ),
* )
*
* @Route("/api/v1/conversations", methods={"GET"})
*/
public function listAction()
{
// ...
}
config:
nelmio_api_doc:
documentation:
models:
use_jms: true
JMS serialize this object just fine.
ConversationRepresentation.php:
/**
* @Serializer\ExclusionPolicy("ALL")
* @Serializer\VirtualProperty("name", exp="object.getName(service('security.token_storage').getToken().getUser(), service('translator'))")
* @Serializer\AccessorOrder("custom", custom = {"id"})
*
* @Hateoas\Relation(
* "lastMessage",
* embedded = "expr(object.getLastMessage())",
* exclusion = @Hateoas\Exclusion(groups={"conversation_list"})
* )
*/
class ConversationRepresentation
{
// ...
}
Solved it. I had to specify JMS Serializer'\Type annotation to make it work
Can you explain more what you did to solve the problem?
I'm having this issue after updating to Symfony 4.1 and I'm confused about how you made it work. Can you give more details @kojiDev ?
I solved it by using the proper annotation, I was using Doctrine. If anyone is having issues follow this documentation https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html
I'm having this issue after updating to Symfony 4.1 and I'm confused about how you made it work. Can you give more details @kojiDev ?
Maybe too late, but here :
nelmio_api_doc:
models: { use_jms: false }
@kojiDev's answer is to had Type annotation on your entity (and it works for me)
(when your entity don't use doctrine)
/**
* @var int
*
* @Serializer\Type("int")
*/
private $id;
Most helpful comment
@kojiDev's answer is to had
Typeannotation on your entity (and it works for me)(when your entity don't use
doctrine)