如何在 swagger ui 中映射这个数组 json?

how to map this array json in swagger ui?

I am working on swagger ui in php and i am trying to map json like below

{
    "category": {
    "id": 0,
    "name": "string"
  }
}

我从 swagger ui 演示中尝试过,但无法像上面那样获得映射 json,我怎样才能得到这个 json 映射,它的注释是什么? 请帮忙

My swagger class is

/**
     * @SWG\Definition(@SWG\Xml(name="MyFl"))
     */ 
    class MyFl
    {

        /**
     * @SWG\Property(format="int64")
     * @var int
     */
    public $id;

    /**
     * @SWG\Property(example="doggie")
     * @var string
     */
    public $name;

    /**
     * @SWG\Property(type="Category")
     */
    public $category;

    }

而我的 post api 注释是:

/**
     * @SWG\Post(
     *   path="/docs/fl",
     *   tags={"MY"},
     *   summary="Insert fl info",
     *   operationId="FL",
     *   produces={"application/xml","application/json"},
     *   @SWG\Parameter(in="body",name="body",description="Insert fl info",required=true,@SWG\Schema(ref="#/definitions/MyFl")
     *   ),
     *   @SWG\Response(response="default", description="successful operation")
     * )
     */

由此我得到如下模型模式:

但我想要 json 架构如下:

 {
        "category": {
        "id": 0,
        "name": "string"
      }
    }

请帮帮我..

免责声明:我已经有很长时间没有使用 swagger-php 注释了,所以我不确定这是最好的方法。我的专长更多是 JSON Schema,而不是 swagger-php。

你的数据结构实际上是两个对象。第一个是带有一个 属性 的对象:"category"。那么"category"的值是另一个对象,它有两个属性:"id"和"name"。我很确定您需要将它们建模为两个单独的对象。

/**
 * @SWG\Definition(@SWG\Xml(name="MyFl"))
 */ 
class MyFl
{

    /**
     * @SWG\Property(type=Category)  <-- Don't know if this is the right way to reference another schema.  You will have to check the documentation.
     */
    public $category;

}

/**
 * @SWG\Definition(@SWG\Xml(name="Category"))
 */ 
class Category
{

    /**
     * @SWG\Property(format="int64")
     * @var int
     */
    public $id;

    /**
     * @SWG\Property(example="doggie")
     * @var string
     */
    public $name;

}

希望对您有所帮助。