导入数据(OpenAPI/Swagger 格式)
/api/v1/projects/{projectId}/import-data
功能说明
当前支持导入 OpenAPI 3、Swagger 1、2、3 格式数据。
调用接口需要个人访问令牌
。查看如何快速上手 IDEA 插件
Swagger 扩展支持
在标准的 Swagger/OpenAPI 基础上增加了如下扩展
一、指定某个接口所属目录:x-apifox-folder
多级目录使用斜杠/
分隔。其中\
和/
为特殊字符,需要转义,\/
表示字符/
,\\
表示字符\
。
"paths": {
"/pets": {
"post": {
...
"operationId": "addPet",
"x-apifox-folder": "宠物店/宠物信息"
}
}
}
二、接口状态:x-apifox-status
状态 | 英文 |
---|---|
设计中 | designing |
待确定 | pending |
开发中 | developing |
联调中 | integrating |
测试中 | testing |
已测完 | tested |
已发布 | released |
已废弃 | deprecated |
有异常 | exception |
已废弃 | obsolete |
将废弃 | deprecated |
"paths": {
"/pets": {
"post": {
...
"operationId": "addPet",
"x-apifox-status": "released"
}
}
}
请求参数
Path 参数
projectId
string
必需
项目 ID,打开 Apifox 进入项目里的“项目设置”查看
示例值:
{{projectId}}
Body 参数application/json
importFormat
string
导入数据格式
目前只支持openapi
,表示 Swagger 或 OpenAPI 格式
枚举值:
openapi
data
string
要导入的数据
Swagger(OpenAPI) 格式 json 字符串,支持 OpenAPI 3、Swagger 1、2、3 数据格式
url
string
可选
数据源 URL,当同时传递 url 和 data 的参数时,会优先使用 url 的数据作为导入数据源
auth
string
可选
数据源 URL 授权用户名和密码
apiOverwriteMode
string or null
覆盖模式
匹配到相同接口时的覆盖模式,不传表示忽略
枚举值:
methodAndPathbothmergeignore
默认值:
ignore
schemaOverwriteMode
string or null
覆盖模式
匹配到相同数据模型时的覆盖模式,不传表示忽略
枚举值:
namebothmergeignore
默认值:
ignore
syncApiFolder
boolean
是否同步更新接口所在目录
默认值:
false
apiFolderId
number
导入到目标目录的ID
不传表示导入到根目录
importBasePath
boolean
是否在接口路径加上basePath
建议不传,即为 false,推荐将 BasePath 放到环境里的”前置 URL“里
默认值:
false
示例
{
"importFormat": "openapi",
"data": "{\"swagger\":\"2.0\",\"paths\":{\"/pet\":{\"post\":{\"summary\":\"Add a new pet to the store\",\"description\":\"\",\"operationId\":\"addPet\",\"parameters\":[{\"in\":\"body\",\"name\":\"body\",\"description\":\"Pet object that needs to be added to the store\",\"required\":true,\"schema\":{\"$ref\":\"#/definitions/Pet\"}}],\"responses\":{\"405\":{\"description\":\"Invalid input\"}}}}},\"definitions\":{\"Pet\":{\"type\":\"object\",\"required\":[\"name\",\"photoUrls\"],\"properties\":{\"id\":{\"type\":\"integer\",\"format\":\"int64\"},\"name\":{\"type\":\"string\",\"example\":\"doggie\"},\"photoUrls\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"xml\":{\"name\":\"photoUrl\"}}},\"status\":{\"type\":\"string\",\"description\":\"pet status in the store\",\"enum\":[\"available\",\"pending\",\"sold\"]}}}}}"
}
示例代码
返回响应
成功(200)
HTTP 状态码: 200
内容格式: JSON
数据结构
data
object {2}
导入结果
apiCollection
object {2}
导入接口情况
schemaCollection
object {2}
导入数据模型情况
success
boolean
接口状态
默认值:
true
示例
{
"data": {
"apiCollection": {
"item": {
"createCount": 0,
"updateCount": 0,
"errorCount": 0,
"ignoreCount": 0
},
"folder": {
"createCount": 0,
"updateCount": 0,
"errorCount": 0,
"ignoreCount": 0
}
},
"schemaCollection": {
"item": {
"createCount": 0,
"updateCount": 0,
"errorCount": 0,
"ignoreCount": 0
},
"folder": {
"createCount": 0,
"updateCount": 0,
"errorCount": 0,
"ignoreCount": 0
}
}
},
"success": "true"
}
修改时间 8 天前