如何使用 Laravel 在 Swagger 中的 post 请求中生成一组对象?
How to generate set array of object in post request in Swagger with Laravel?
我正在尝试使用 Laravel 模型中的正文请求在 Laravel-5.5 Swagger 中生成对象数组。
我应该如何达到预期的输出??
[
{
"user_name": "string",
"education": [
{
"degree": [
{
"year": "string",
"name": "string"
},
{
"year": "string",
"name": "string"
}
],
"hobby": [
{
"type": "string",
"description": "string"
},
{
"type": "string",
"description": "string"
}
]
}
]
}
]
谁能帮帮我?
谢谢。
在 "User" 模型中,您只需将其放在代码下方即可。
/**
* @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,
我正在尝试使用 Laravel 模型中的正文请求在 Laravel-5.5 Swagger 中生成对象数组。
我应该如何达到预期的输出??
[
{
"user_name": "string",
"education": [
{
"degree": [
{
"year": "string",
"name": "string"
},
{
"year": "string",
"name": "string"
}
],
"hobby": [
{
"type": "string",
"description": "string"
},
{
"type": "string",
"description": "string"
}
]
}
]
}
]
谁能帮帮我?
谢谢。
在 "User" 模型中,您只需将其放在代码下方即可。
/**
* @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,