Search code examples
swaggerswagger-uiswagger-php

SWAGGER-PHP error when generating .json I can not load the values from my model


Hi guys I tried to eliminate this error that persists when I generate the swagger.json, the error says:

[WARN] [Syntax Error] Expected Value, got '@' in \App\Http\Controllers... and in my code, OHH iM WORKING WITH LUMEN.

/**
 * @SWG\Put(
 *   path="/v1/resource/{id1}/rsc/{id2}",
 *   summary="Update ...",
 *   operationId="update",
 *   tags={"Update"},  
 *
 *
 *   @SWG\Response(response=200, description="Json [client] "),
 *   @SWG\Response(response=404, description="Recurso no encontrado"),
 *   @SWG\Response(response=500, description="[error] Error interno del servidor"),
 *   @SWG\Parameter(
 *     name="id1",
 *     in="path",
 *     description="Id1.",
 *     required=true,
 *     type="integer"
 *   ),
 *   @SWG\Parameter(
 *     name="id2",
 *     in="path",
 *     description="Id2",
 *     required=true,
 *     type="integer"
 *   ),
 *   @SWG\Parameter(
 *     name="JSON update body",
 *     in="body",
 *     description="Request.",
 *     required=true,
 *     @SWG\Schema(type="array",@Model(type=vendor\LibModel\DAO\src\Model\Hospital))
 *   )
 *  )
 */
 public function update($id1,$id2, Request $request){...}

When I check the json does not generate the definitions -> "definitions": {}. My model defined it in the following way, I do not know if the problem is that my model is under a different namespace because it is defined as a vendor or something declarative that I lack:

/**
 * Class Hospital
 *
 *
 * @SWG\Definition(
 *   definition="Hospital"
 * )
 *
 */
class Hospital extends Model
{

    /**
     * @SWG\Property(format="string")
     * @var string
     */
    protected $name;

    /**
     * @SWG\Property(format="string")
     * @var string
     */
    protected $email;

..and in my view of swagger m an ERROR appears ... I think it's because it does not load the values of the model, thanks to who can help me


Solution

  • The doctrine parser complains about @Model which is not part of swagger-php.

    The swagger-php notation is:

     * @SWG\Parameter(
     *     name="JSON update body",
     *     in="body",
     *     description="Request.",
     *     required=true,
     *     @SWG\Schema(
     *         type="array",
     *         @SWG\Items(ref="#/definitions/Hospital")
     *     )
     * )
    

    I've wan't to use NelmioApiDocBundle (which uses that @Model annotation) check their guides to see how to set that up.