laravel - 如何在laravel中大摇大摆地制作对象?
问题描述
我使用swagger
inlaravel
并且想显示这个 json 响应:
{
"status": "yearly",
"result": [
{
"visitCount": {
"1399": 31,
"1400": 1
},
"visitorCount": {
"1399": 30,
"1400": 1
},
"submitCount": {
"1399": 22,
"1400": 1
}
}
]
}
result
包含 ( visitCount
, visitorCount
, submitCount
) ,我想为每个对象创建一个对象。例如:
"visitCount": {
"1399": 31,
"1400": 1
}
我不能在swaager
. 你可以帮帮我吗。
我的代码是:
@OA\Response(
response=200,
description="ok",
@OA\JsonContent( anyOf={
@OA\Schema(
type="object",
@OA\Property(property="status", type="string", default="yearly"),
@OA\Property(property="result", type="array",
@OA\Items(type="object",
@OA\Property(property="visitCount", type="object"),
@OA\Property(property="visitorCount", type="object"),
@OA\Property(property="submitCount", type="object")
),
),
),
解决方案
您可以将其添加到您的示例字段中。
@OA\Property(property="visitCount", type="string", format="array", example={"1399":"1","1400":"2"})