我想將我的API文檔分解成多個可以獨立編輯的JSON文件。我所能找到的所有示例都使用Swagger 1.2模式,該模式具有「api」:{}對象來分解它。這似乎從2.0架構中缺少(http://json.schemastore.org/swagger-2.0)。所有定義的都是單個「路徑」數組,它將所有API端點捆綁到單個數組中。這在swagger-ui中的效果是有一個單一的「默認」類別,所有東西都被捆綁到了一起,而我沒有辦法將其分解。如何將Swagger 2.0 JSON文件分解成多個模塊
TLDR:你如何招搖2.0架構
{
"swagger": "2.0",
"info": {
"description": "My API",
"version": "1.0.0",
"title": "My API",
"termsOfService": "http://www.domain.com",
"contact": {
"name": "[email protected]"
}
},
"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"
}
}
}
}
}
}
}
因此,如果我想爲每個標籤有單獨的文件,這是可能的嗎?我可以看到使用$ ref將所有資源(例如)放入單獨的文件中,但是如何拆分「路徑」數組? –
你不能那樣做。再次,微服務解決方案即將推出,但這並不一定意味着標籤==微服務。 – Ron
你可以在不同的文件中定義路徑和模型嗎?在swagger 2.0中的例子? – lostintranslation