yapi
yapi copied to clipboard
导入swagger3.0的接口文档时对于allof字段解析似乎有问题?
版本号
yapi: 由于不方便查看yapi项目的信息,所以版本未知,但是应该是比较新的版本,今年的项目,而且导入的时候显示支持swagger v2.0+
swagger/openapi: "3.0.0"
什么问题
两个接口的返回结果schema结构继承了基础的返回结果schema结构,即:
/components/schemas/List1Response
和/components/schemas/List2Response
继承了
/components/schemas/BaseResponse
,
然后导入后,两个接口的都互相包含了对方的接口字段,即接口1包含了接口2的返回字段,接口2包含了接口1的返回字段,在我的示例代码中,即为get-list1
包含了p2
字段,get-list2
包含了p1
字段,而期望的结果应该是get-list1
只包含p1字段,get-list2
只包含p2字段 ,我看各种资料,想要实现继承好像是用allof
来实现吧?难道是我搞错了?麻烦yapi的开发人员大佬们帮忙看看!多谢了!
见截图:
什么浏览器
chrome
代码
生成的接口文档json文件
{
"openapi": "3.0.0",
"info": {
"title": "业务迭代",
"version": "0.1"
},
"paths": {
"/get-list1": {
"post": {
"summary": "列表1",
"operationId": "/get-list1",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"app": {
"type": "integer"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/List1Response"
}
}
}
}
}
}
},
"/get-list2": {
"post": {
"summary": "列表2",
"operationId": "/get-list2",
"requestBody": {
"content": {
"application/json": {
"schema": {
"properties": {
"app": {
"type": "integer"
}
},
"type": "object"
}
}
}
},
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/List2Response"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"BaseResponse": {
"required": [
"code",
"msg",
"data"
],
"properties": {
"code": {
"description": "结果码",
"type": "integer"
},
"msg": {
"description": "结果信息",
"type": "string"
},
"data": {
"description": "结果数据",
"type": "object"
}
},
"type": "object"
},
"List1Response": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/BaseResponse"
},
{
"properties": {
"data": {
"properties": {
"p1": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
]
},
"List2Response": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/BaseResponse"
},
{
"properties": {
"data": {
"properties": {
"p2": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
]
}
}
}
}
定义代码
统一接口返回结果结构体
@OA\Schema(
schema="BaseResponse",
type="object",
required={"code","msg","data"},
@OA\Property(
property="code",
type="integer",
description="结果码",
),
@OA\Property(
property="msg",
type="string",
description="结果信息",
),
@OA\Property(
property="data",
type="object",
description="结果数据",
),
)
@OA\Post(
path="/get-list1",
summary="列表1",
@OA\RequestBody(
@OA\MediaType(
mediaType="application/json",
@OA\Schema(
@OA\Property(
property="app",
type="integer",
default=0,
),
)
)
),
@OA\Response(
response=200,
description="OK",
@OA\JsonContent(ref="#/components/schemas/List1Response")
),
)
返回结果
@OA\Schema(
schema="List1Response",
type="object",
allOf={
@OA\Schema(ref="#/components/schemas/BaseResponse"),
@OA\Schema(
@OA\Property(
property="data",
type="object",
@OA\Property(
property="p1",
type="string",
),
)
)
}
)
@OA\Post(
path="/get-list2",
summary="列表2",
@OA\RequestBody(
@OA\MediaType(
mediaType="application/json",
@OA\Schema(
@OA\Property(
property="app",
type="integer",
default=0,
),
)
)
),
@OA\Response(
response=200,
description="OK",
@OA\JsonContent(ref="#/components/schemas/List2Response")
),
)
返回结果
@OA\Schema(
schema="List2Response",
type="object",
allOf={
@OA\Schema(ref="#/components/schemas/BaseResponse"),
@OA\Schema(
@OA\Property(
property="data",
type="object",
@OA\Property(
property="p2",
type="string",
),
)
)
}
)
我的也遇到的同样的问题,你的解决了吗?
我导入Swagger 3.0的response数据yapi显示的都是OK,没有解析到返回实体,换回2.x版本才可以解析response实体
我导入Swagger 3.0的response数据yapi显示的都是OK,没有解析到返回实体,换回2.x版本才可以解析response实体
我和你一样,导入OpenAPI 3.0的接口,界面显示ok,但是response object没有被自动解析。 2.0还是很ok的。
问题还存在,生成swagger文档没问题。 感觉yapi导入时,解引用的bug