How to generate set array of object in post request in Swagger with Laravel?

左心房为你撑大大i 提交于 2019-12-10 18:38:03

问题


I am trying to generate array of object in Laravel-5.5 Swagger using body request in Laravel Model.

How should i achieve desired output ??

[
  {
    "user_name": "string",
    "education": [
      {
        "degree": [
          {
            "year": "string",
            "name": "string"
          },
          {
            "year": "string",
            "name": "string"
          }
        ],
        "hobby": [
          {
            "type": "string",
            "description": "string"
          },
          {
            "type": "string",
            "description": "string"
          }
        ]
      }
    ]
  }
]

can anyone please help me ?

Thanks.


回答1:


In "User" model you just need to put this below code.

/**
 *  @SWG\Definition(
 *      definition="User",
 *      type="array",
 *      @SWG\Items(
 *          type="object",
 *          @SWG\Property(type="string", property="user_name", description="User name"),
 *          @SWG\Property(type="array", property="education", description="Education",
 *              @SWG\Items(
 *                  @SWG\Property(property="degree", type="object",
 *                      type="array",
 *                      @SWG\Items(
 *                          @SWG\Property(property="year", type="string"),
 *                          @SWG\Property(property="name", type="string"),
 *                      ),
 *                  ),
 *                  @SWG\Property(property="hobby", type="object",
 *                      type="array",
 *                      @SWG\Items(
 *                          @SWG\Property(property="type", type="string"),
 *                          @SWG\Property(property="description", type="string"),
 *                      ),
 *                  ),
 *              ),
 *          ),
 *      ),
 * ),
 */
class User extends Model
{
   //
}

In above code while you send request that time you just need to edit. After copy paste after immidiate degree object with ",". Then you can pass multiple object in array.

Thanks,



来源:https://stackoverflow.com/questions/49043544/how-to-generate-set-array-of-object-in-post-request-in-swagger-with-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!