【问题标题】:@Swagger\Annotations\Example" doesn't exist error@Swagger\Annotations\Example" 不存在错误
【发布时间】: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


【解决方案1】:

你可以试试这个。

    /**
     * @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")
     *       ),
     *        example={
     *            "data": {
     *            "api_token": "ffdca087b7f97117330824ceea948a99",
     *            "id": "1",
     *            "email": "joe@doe.com",
     *            "first_name": "Joe",
     *            "last_name": "Doe"
     *            }
     *        }
     *   )

【讨论】:

  • [INFO] @SWG\Parameter(name="pet",in="body") 的意外字段“示例”,期望“ref”、“parameter”、“name”、“in ", "description", "required", "schema", "type", "format", "allowEmptyValue", "items", "collectionFormat", "default", "maximum", "exclusiveMaximum", "minimum", src/info.php 第 35 行中的“exclusiveMinimum”、“maxLength”、“minLength”、“pattern”、“maxItems”、“minItems”、“uniqueItems”、“enum”、“multipleOf”、“x” [警告] [语法错误] 预期的 Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS,在第 35 行的 src/info.php 中获得了字符串的结尾。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-31
  • 1970-01-01
  • 2017-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-14
相关资源
最近更新 更多