3

模型的示例招摇标记

* @SWG\Model(
 * id="UserSubscriptionSearchResultsFilter",
 *  @SWG\Property(name="total", type="integer"),
 *  @SWG\Property(name="perPage", type="integer"),
 *  @SWG\Property(name="query", type="string"),
 *  @SWG\Property(name="sortColumn", type="string"),
 *  @SWG\Property(name="sortDirection", type="string"),
 * )
 */

/**
 * @SWG\Model(
 * id="UserSubscriptionSearchResults",
 *  @SWG\Property(name="results",type="array", items="$ref:UserSubscriptionRepository"),
 *  @SWG\Property(name="total", type="integer"),
 *  @SWG\Property(name="filter",type="object", uniqueItems="$ref:UserSubscriptionSearchResultsFilter")
 * )
 */

现在架构看起来像:

"filter": "object"

相反,我想看到的是:

"filter":  {
        "total": 0,
        "perPage": 0,
        "query": "",
        "sortColumn": "",
        "sortDirection": ""
      }

现在我只能创建一个看起来与此相对相似的数组对象,但它仍然不是完整的规范。

我在这里读过类似的问题: https ://github.com/swagger-api/swagger-spec/issues/38 https://github.com/mission-liao/pyswagger/issues/18

但我还没有找到明确的答案。

4

1 回答 1

1

Swagger 2.0 中的正确架构在您的情况下应该类似于:

"definitions": {
  "filter": {
    "type": "object",
    "properties": {
       "total": {
          "type": "integer"
       },
       "perPage": {
          "type": "integer"
       },
       "query": {
          "type": "string"
       },
       "sortColumn": {
          "type": "string"
       },
       "sortDirection": {
          "type": "string"
       }
    }
  }
}

我猜你使用的项目是swagger-php。这是他们从此处声明模型的示例中的引用:

<?php
namespace PetstoreIO;
/**
 * @SWG\Definition(
 *   @SWG\Xml(name="Category")
 * )
 */
class Category
{
    /**
     * @SWG\Property(format="int64")
     * @var int
     */
    public $id;
    /**
     * @SWG\Property()
     * @var string
     */
    public $name;
}

从 1.2 升级到 2.0 时,术语从“模型”更改为“定义”。

于 2015-09-23T04:31:44.650 回答