3

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
  • Please check my answer below and solved your issue. Commented Mar 1, 2018 at 6:14

1 Answer 1

4

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,

Sign up to request clarification or add additional context in comments.

3 Comments

let me implement
Okay, If you get stuck then let me know same. so I can help you more about swagger.
Yes, you will get json response from this swagger comment code in laravel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.