我正在使用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)
{