@@ ApiProperty openapi_context类型数组示例

问题描述 投票:1回答:1

是否可以为@ApiProperty创建openapi_context“ type” =“ array”?使用注释写入此类数组的“示例”值的正确方法是什么?我正在使用OAS3

/**
 * @ApiProperty(
 *     attributes={
 *      "openapi_context"={
 *        "type"="array",
 *        "example"="array example goes here"
 *      }
 *     }
 * )
 *
 * @var array<array>
 */
php annotations openapi api-platform.com
1个回答
0
投票

我不确定您的问题,因为我不知道您数组的内容。如果这不能回答您的问题,请随时添加评论。

数组类型

OpenApi Specification定义的原始数据类型记录在this chapter中。没有提到数组,当然是因为这不是原始数据类型。

因为,如果您查看schema 3.0,则架构的Line 203描述开始。接受数组(Line 263)。因此,是的,可以为@ApiProperty

创建openapi_context“ type” =“ array”

示例并且,如果您查看schema 3.0,则示例(Line 323)是没有说明的对象。这样您就可以编写所需的内容。我不是一个忠实拥护者,很多文档使用示例来提供可接受的价值。

因此,我使用尊重OAS3的Swagger。数组为documented,您可以在注释中找到一些示例。 Somme示例在“注释”中定义。这些示例来自Swagger文档。

  • [整数"[ 1, 2, 3, 4 ]"数组的示例
  • 对象"[ {"id": 5}, {"id": 8} ]"的数组的示例
  • 整数"[ [1, 2], [3, 4] ]"的数组的例子

对于多维数组,这是招摇的上下文:

    # [ [1, 2], [3, 4] ]
    type: array
    items:
      type: array
      items:
        type: integer

注解是:

    /**
     * @ApiProperty(
     *     attributes={
     *      "openapi_context"={
     *        "type"="array",
     *        "items" = {"type"="array", "items"={"type"={"integer","string"}}},
     *        "example"="[[1,'foo'], ['bar',4, 5]]"
     *      }
     *     }
     * )
     * @ORM\Column(type="array")
     */

我创建了一个实体,该实体的属性是包含字符串或整数的多维数组。 ((字符串或整数)数组的数组),然后获取招摇文档的屏幕截图。好像很好!

示例结果是:

Sample screenshot

生成的模式是:

Schema screenshot

The example are well documented,您可以找到数组的答案。

© www.soinside.com 2019 - 2024. All rights reserved.