Swagger PHP - 如何定义嵌套 属性?
Swagger PHP - how to define a nested property?
我正在使用 Swagger PHP 并且大多数定义都很容易定义,但是我对不属于单独 class 的特定数据片段有疑问,而是一个关联数组。
我希望显示的 json 回复(针对此问题进行了简化):
{
"id": 1,
"status": "published",
"gps": {
"lat": "0.00000000",
"lng": "0.00000000"
}
id
和 status
很容易定义,但是 gps
是个问题,因为没有单独的 class 来定义它,它是模型中的数组。是否可以定义此数组而不必创建虚拟 class?
当前模型文件中的注释:
/**
* @SWG\Definition(@SWG\Xml(name="Event"))
*/
class Event extends BaseModel {
/**
* @SWG\Property(
* property="id",
* type="integer",
* example="103"
* )
* @SWG\Property(
* property="status",
* type="string",
* enum={"published", "draft", "suspended"}
* example="published"
* )
*/
}
遇到完全相同的问题,今天解决了!
This is for Swagger 2.0
下面是我用来实现参数嵌套的注解嵌套..
/**
* @SWG\Post(
* path="/getCustomerByEmail.php",
* summary="List the details of customer by the email.",
* consumes={"string"},
* produces={"application/json"},
* @SWG\Parameter(
* name="email",
* in="body",
* description="Customer email to ge the data",
* required=true,
* @SWG\Schema(
* @SWG\Property(
* property="id",
* type="object",
* @SWG\Property(
* property="abc",
* type="object",
* @SWG\Property(
* property="inner abc",
* type="number",
* default=1,
* example=123
* )
* ),
* @SWG\Property(
* property="xyz",
* type="string",
* default="xyz default value",
* example="xyz example value",
* )
* )
* )
* ),
* @SWG\Response(
* response=200,
* description="Details of the customer"
* ),
* @SWG\Response(
* response=400,
* description="Email required"
* ),
* @SWG\Response(
* response=404,
* description="Customer does not exist"
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
/**
Note: I was working on a project which required raw PHP but still
wanted to use Swagger. So instead of creating the models, I used this
technique to make the nested parameters.
编辑 1:我不知道有什么问题,UI 符合预期,但是在发出请求时,post 或有效负载中没有数据。
编辑 2:将 Get 转换为 Post。
适用于 file_get_contents("php://input")
我正在使用 Swagger PHP 并且大多数定义都很容易定义,但是我对不属于单独 class 的特定数据片段有疑问,而是一个关联数组。
我希望显示的 json 回复(针对此问题进行了简化):
{
"id": 1,
"status": "published",
"gps": {
"lat": "0.00000000",
"lng": "0.00000000"
}
id
和 status
很容易定义,但是 gps
是个问题,因为没有单独的 class 来定义它,它是模型中的数组。是否可以定义此数组而不必创建虚拟 class?
当前模型文件中的注释:
/**
* @SWG\Definition(@SWG\Xml(name="Event"))
*/
class Event extends BaseModel {
/**
* @SWG\Property(
* property="id",
* type="integer",
* example="103"
* )
* @SWG\Property(
* property="status",
* type="string",
* enum={"published", "draft", "suspended"}
* example="published"
* )
*/
}
遇到完全相同的问题,今天解决了!
This is for Swagger 2.0
下面是我用来实现参数嵌套的注解嵌套..
/**
* @SWG\Post(
* path="/getCustomerByEmail.php",
* summary="List the details of customer by the email.",
* consumes={"string"},
* produces={"application/json"},
* @SWG\Parameter(
* name="email",
* in="body",
* description="Customer email to ge the data",
* required=true,
* @SWG\Schema(
* @SWG\Property(
* property="id",
* type="object",
* @SWG\Property(
* property="abc",
* type="object",
* @SWG\Property(
* property="inner abc",
* type="number",
* default=1,
* example=123
* )
* ),
* @SWG\Property(
* property="xyz",
* type="string",
* default="xyz default value",
* example="xyz example value",
* )
* )
* )
* ),
* @SWG\Response(
* response=200,
* description="Details of the customer"
* ),
* @SWG\Response(
* response=400,
* description="Email required"
* ),
* @SWG\Response(
* response=404,
* description="Customer does not exist"
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
/**
Note: I was working on a project which required raw PHP but still wanted to use Swagger. So instead of creating the models, I used this technique to make the nested parameters.
编辑 1:我不知道有什么问题,UI 符合预期,但是在发出请求时,post 或有效负载中没有数据。
编辑 2:将 Get 转换为 Post。
适用于 file_get_contents("php://input")