-1

我正在使用 NelmioApiDoc 包编写 API 文档。一切都很好,除了一件事:使用注释在模式中标记必填字段。我有以下注释:

[...]
  * @SWG\Parameter(
  *     name="Some parameter",
  *     in="body",
  *     required=true,
  *     @SWG\Schema(
  *         type="object",
  *         required="<how to put array of strings here?>",
  *         @SWG\Property(
  *             property="thisIsRequired",
  *             type="string",
  *         ),
  *         @SWG\Property(
  *             property="thisIsOptional",
  *             type="string",
  *         ),
[...]

我想根据需要标记“thisIsRequired”。使用required=trueon 属性不是正确的方法,因为它应该放在 Schema 级别。

如果我使用 yaml 一切都很好:

# packages/nelmio_api_doc.yaml
[...]
  schema:
    type: object
    required:
      - thisIsRequired
[...]

并且必填字段用红色星号正确标记。我正在努力使用 PHPDoc:/ 我尝试过:

required="[\"thisIsRequired\"]", // wrong syntax
required=["thisIsRequired"]", // wrong syntax
required=array(\"thisIsRequired\"), // wrong syntax
required=array(thisIsRequired), // wrong syntax
required="array(\"thisIsRequired\")", // wrong syntax

required={"thisIsRequired"}, // no exception but doesnt mark field as required
required="[thisIsRequired]", // no exception but doesnt mark field as required
required="thisIsRequired", // no exception but doesnt mark field as required
4

1 回答 1

2

原来这是正确的语法:

required={"thisIsRequired", "otherField"},

那一次尝试后我可能没有清除缓存。请记住,孩子们总是在更改后清除您的缓存!;)

于 2020-06-09T06:01:51.967 回答