如何使用Laravel在Swagger中的后期请求中生成对象的设置数组? [英] How to generate set array of object in post request in Swagger with Laravel?

查看:391
本文介绍了如何使用Laravel在Swagger中的后期请求中生成对象的设置数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel模型中的主体请求在Laravel-5.5 Swagger中生成对象数组.

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"
          }
        ]
      }
    ]
  }
]

有人可以帮助我吗?

谢谢.

推荐答案

在用户"模型中,您只需将其放在下面的代码中即可.

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.

谢谢

这篇关于如何使用Laravel在Swagger中的后期请求中生成对象的设置数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆