如何在swagger ui中映射此数组json? [英] how to map this array json in swagger ui?
问题描述
我正在使用PHP中的swagger ui,并且我正在尝试将json映射为 下方
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映射,它的注释是什么? 请帮助
I tried it from swagger ui demos but unable to get mapping like above json, how can i get this json mapping, what would be the annotation for that ? please help
我的招摇类是
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注释是:
And my post api annotation is:
/**
* @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")
* )
*/
通过这种方式,我得到的模型模式如下:
And by this i am getting model schema like:
但是我想要像这样的json模式:
But i want json schema like:
{
"category": {
"id": 0,
"name": "string"
}
}
请帮助我.
推荐答案
免责声明:自从我使用swagger-php批注以来已经很长时间了,所以我不确定这是实现此目的的最佳方法.我的专长是JSON Schema,而不是swagger-php.
DISCLAIMER: It's been a long time since I worked with swagger-php annotations, so I'm not sure this is the best way to do this. My expertise is more in JSON Schema, not swagger-php.
您的数据结构实际上是两个对象.第一个是具有一个属性的对象:类别".然后,"category"的值是具有两个属性的另一个对象:"id"和"name".我很确定您需要将它们建模为两个单独的对象.
Your data structure is actually two objects. The first is an object with one property: "category". Then the value of "category" is another object with two properties: "id" and "name". I'm pretty sure you need to model these as two separate objects.
/**
* @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;
}
希望有帮助.
这篇关于如何在swagger ui中映射此数组json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!