我正忙于了解 swagger.json 规范是如何工作的(在我的例子中是 api.json)。在研究过程中,我可以找到许多关于如何处理 GET 请求的示例,但对于 POST 或其他任何内容都没有。我的迫切需要是实现 POST 部分,但我觉得我需要更好地理解这一点,而不是复制和粘贴代码并依靠反复试验来使其工作。Swagger.io 网站上的内容对初学者不友好。有人可以解释下面的示例代码中发生了什么,特别是在两种情况下的“get:”之后:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "FoodTrucks",
"description": "An TryApp sample API App where you can find Food trucks."
},
"host": "microsoft-apiapp1fe6951749ff4b76b8cc9194bc29ba61.azurewebsites.net:443",
"schemes": ["http", "https"],
"basePath": "/api/data",
"paths": {
"/foodtrucks": {
"get": {
"tags": ["FoodTrucks"],
"operationId": "getFoodTrucks",
"consumes": [],
"produces": ["application/json",
"text/json",
"application/xml",
"text/xml"],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Restaurant"
}
}
}
},
"deprecated": false
}
},
"/foodtrucks/{id}": {
"get": {
"tags": ["FoodTrucks"],
"operationId": "getFoodTruckDetails",
"consumes": [],
"produces": ["application/json",
"text/json",
"application/xml",
"text/xml"],
"parameters": [{
"name": "id",
"in": "path",
"required": true,
"type": "integer",
"format": "int32"
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Restaurant"
}
}
}
},
"deprecated": false
}
}
},
"definitions": {
"Restaurant": {
"type": "object",
"properties": {
"id": {
"format": "int32",
"type": "integer"
},
"name": {
"type": "string"
},
"likes": {
"format": "int32",
"type": "integer"
},
"savory": {
"type": "boolean"
},
"sweet": {
"type": "boolean"
},
"vegetarian": {
"type": "boolean"
},
"bookable": {
"type": "boolean"
},
"city": {
"type": "string"
}
}
}
}
}
请您也可以提供一个简单的 POST 示例。