gpt4 book ai didi

php - 如何使用 Laravel 在 Swagger 的 post 请求中生成一组对象?

转载 作者:行者123 更新时间:2023-12-04 22:32:39 25 4
gpt4 key购买 nike

我正在尝试使用 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"
}
]
}
]
}
]

谁能帮帮我?

谢谢。

最佳答案

在“用户”模型中,您只需将其放在代码下方即可。

/**
* @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,

关于php - 如何使用 Laravel 在 Swagger 的 post 请求中生成一组对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49043544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com