2

I'm using Nelmio API docs to generate the documentation for my REST api using FOSRestBundle and JMSSerializer. The docs generated say my json objects are actually arrays. How do I make the documentation say my objects are objects?

I know under the hood, in php these fields are actually key-value associative arrays, but in the actual json they are objects and I'd like my documentation to reflect that.

Here is my code entity:

/**
 *
 * 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;
...
}

controller:

/**
 * 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)
{
James
  • 197
  • 2
  • 13

0 Answers0