我正在使用 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=true
on 属性不是正确的方法,因为它应该放在 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