Swagger PHP object instead of array

Example of markup 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")
 * )
 */

      

The current diagram looks like this:

"filter": "object"

      

Instead, I want to see:

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

      

Right now I have managed to create an array object that looks relatively similar to it, but it is still not complete.

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

But I haven't found a clear answer.

+3


source to share


1 answer


The correct layout in Swagger 2.0 in your case should look something like this:

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

      

I am assuming the project you are using is swagger-php . Here's 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 change from "model" to "definition" when upgrading from 1.2 to 2.0.

+1


source







All Articles