【问题标题】:Swagger PHP annotation for object of array数组对象的 Swagger PHP 注释
【发布时间】:2020-02-18 06:31:07
【问题描述】:

我想在 api/doc 视图中包含对象数组。但我无法理解。

从下面的代码:

@SWG\Schema(        
  @SWG\Property(property="project-name", type="string"),    
  @SWG\Property(property="project-detail", type="array",
    @SWG\Items(type="object",
        @SWG\Property(property="name", type="string", ),
        @SWG\Property(property="category", type="string",),
    ),
    @SWG\Items(type="object",
        @SWG\Property(property="new_name", type="string", ),
        @SWG\Property(property="new_category", type="string",),
    ),
  ),
),

我得到了输出:

{
  "project-name": "string",
  "project-detail": [
     {
       "name": "string",
       "category": "string"
     }
   ]
}

但我想要以下一个:

{
  "project-name": "string",
  "project-detail": [
     {
       "name": "string",
       "category": "string"
     },
     {
       "new_name": "string",
       "new_category": "string"
     },
   ]
}

请帮帮我。

【问题讨论】:

标签: annotations swagger-php nelmioapidocbundle


【解决方案1】:

您只能在对象数组上显示一个对象。因为创建 Swagger 是为了解释您必须向 API 提供什么以及返回什么(不是必需的)。

当您查看一个数组和其中的一个对象时,您当然会理解这不是一个包含 1 个对象的数组。

希望对你有帮助!

主啊

【讨论】:

    【解决方案2】:

    通过添加示例 ex. 来修改您的项目详细信息属性。

    example="{
             {
              "name": "String",
              "category": "String"
             }, 
             {
              "name": "String",
              "category": "String"
             }
            }"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 2016-06-05
      • 2021-12-27
      • 2020-03-03
      相关资源
      最近更新 更多