【发布时间】:2017-11-16 09:57:28
【问题描述】:
我正在使用带有 PHP 注释的 Swagger v.2,现在我在请求正文中遇到了一个“示例”的小问题。
在我的控制器中是这样的:
/**
* @SWG\Post(
* tags={"pet"},
* path="/pet",
* summary="Create a pet",
* description="Create a pet",
* operationId="CreatePet",
* consumes={"application/json"},
* produces={"application/json"},
* @SWG\Parameter(
* name="pet",
* required=true,
* in="body",
* description="Pet object to be created",
* @SWG\Schema(
* @SWG\Property(property="pet",ref="#/definitions/Pet")
* ),
* @SWG\Example(
* ref="somepath/pet.json"
* )
* )
我需要根据特定条件有不同的模式示例,这就是为什么我希望在一个单独的 json 文件中说明模式示例,该文件将以这种方式引用。我从this link 得到这个想法。
但是,这不起作用,我收到The annotation "@Swagger\Annotations\Example" doesn't exist 错误。
如果有人知道应该如何使用注释修复它,我们将不胜感激。
谢谢
【问题讨论】:
-
仅供参考 - 您链接到的规范是 OpenAPI 3.0,而不是 OpenAPI/Swagger 2.0(您正在使用)。 OpenAPI/Swagger 2.0 需要内联示例,它不支持单独文件中的模式示例。
标签: php swagger swagger-2.0 swagger-php