我正在尝试将我的 API 文档分解为多个可以独立编辑的 JSON 文件。我能找到的所有示例都使用 Swagger 1.2 模式,它有一个“api”:{} 对象来分解它。2.0 模式 ( http://json.schemastore.org/swagger-2.0 )似乎缺少这点。所定义的只是一个单一的“路径”数组,它将所有 API 端点捆绑到该单一数组中。这在 swagger-ui 中的效果是有一个单一的“默认”类别,所有东西都被捆绑到其中,我无法告诉将其拆分。
TLDR:如何从 swagger 2.0 模式中的路径拆分操作
{
"swagger": "2.0",
"info": {
"description": "My API",
"version": "1.0.0",
"title": "My API",
"termsOfService": "http://www.domain.com",
"contact": {
"name": "support@domain.com"
}
},
"basePath": "/",
"schemes": [
"http"
],
"paths": {
"Authorization/LoginAPI": {
"post": {
"summary": "Authenticates you to the system and produces a session token that will be used for future calls",
"description": "",
"operationId": "LoginAPI",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/json"
],
"parameters": [{
"in": "formData",
"name": "UserName",
"description": "Login Username",
"required": true,
"type": "string"
}, {
"in": "formData",
"name": "Password",
"description": "Password",
"required": true,
"type": "string"
}],
"responses": {
"200": {
"description": "API Response with session ID if login is allowed",
"schema": {
"$ref": "#/definitions/Authorization"
}
}
}
}
}
}
}