Nelmioapidocbundle: Empty json object {} when specifying @Model

Created on 5 Aug 2017  路  6Comments  路  Source: nelmio/NelmioApiDocBundle

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
{
// ...
}

Most helpful comment

@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;

All 6 comments

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;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

smuralidharan picture smuralidharan  路  3Comments

DavidGarciaCat picture DavidGarciaCat  路  4Comments

manseuk picture manseuk  路  6Comments

andydandy80 picture andydandy80  路  4Comments

jhkchan picture jhkchan  路  4Comments