2

我正在使用 Nelmio API 文档使用 FOSRestBundle 和 JMSSerializer 为我的 REST api 生成文档。生成的文档说我的 json 对象实际上是数组。如何让文档说我的对象是对象?

我知道,在 php 中,这些字段实际上是键值关联数组,但在实际的 json 中,它们是对象,我希望我的文档能够反映这一点。

这是我的代码实体:

/**
 *
 * Class Facility
 * @package Company\Bundle\RestApiBundle\Entity
 *
 * @Serializer\XmlRoot("facility")
 *
 * @Hateoas\Relation("self", href = "expr('/facility/' ~ object.getId())")
 * @Hateoas\Relation(
 *     "units",
 *     embedded = "expr(object.getUnits())"
 * )
 * @Hateoas\Relation(
 *     "reviews",
 *     embedded = "expr(object.getReviews())"
 * )
 *
 */
class Facility
{
...
    /**
     * @var
     * @Serializer\Type("array")
     */
    protected $amenities;
...
}

控制器:

/**
 * Resource describing the Facility object
 *
 * @ApiDoc(
 *   resource = true,
 *   resourceDescription="Operations on facilities.",
 *   description = "Facility object",
 *   output = "Company\Bundle\RestApiBundle\Entity\Facility",
 *   statusCodes = {
 *     200 = "Returned when successful",
 *     404 = "Returned when the resource is not found"
 *   }
 * )
 *
 * @param $id
 * @return \Symfony\Component\HttpFoundation\Response
 *
 * @Method("GET")
 * @Route("/{id}", name = "api_facility_get")
 */
public function getFacilityAction($id)
{
4

0 回答 0