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.
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,