3

Example swagger markup for a model

* @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")
 * )
 */

Right now the schema looks like:

"filter": "object"

Instead what I want to see is:

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

Right now I've only been able to create an array object that looks relatively similar to this, but it is still not full spec.

I've read similar issues here: https://github.com/swagger-api/swagger-spec/issues/38 https://github.com/mission-liao/pyswagger/issues/18

But I've not found a clear answer.

1 Answer 1

2

The correct schema in Swagger 2.0 is in your case should be something like:

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

I guess the project you use is swagger-php. Here is a quote from their example for declaring a model from here:

<?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;
}

The terms are changed from "model" to "definition" when upgrading from 1.2 to 2.0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.