本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
匯入API文件
與匯入API實體定義一樣,您可以將文件部分從外部開啟API檔案匯入到 API Gateway API 中。您可以在有效的「開啟」定API義檔案中指定x-amazon-apigateway-documentation 物件副檔名內的 to-be-imported 文件零件。匯入文件不會改變現有的API實體定義。
您可以選擇將新指定的文件部分合併到 API Gateway 中的現有文件集部分,或覆寫現有的文件集部分。在MERGE
模式中,在「開啟」API 檔案中定義的新文件零件會加入到的DocumentationParts
集合中API。如果匯入的 DocumentationPart
已存在,匯入的屬性會取代現有的屬性 (如果兩者不同)。其他現有的文件屬性則不受影響。在OVERWRITE
模式下,會根據匯入的「開啟」(Open) API 定義檔案取代整個DocumentationParts
集合。
使用API閘道匯入文件組件 REST API
若要使用API閘道匯入API文件 RESTAPI,請呼叫文件部分:匯入作業。下列範例顯示如何使用單一GET /
方法覆寫現API有的文件部分,並在成功時傳回回200 OK
應。
- OpenAPI 3.0
-
PUT /restapis/<restapi_id>/documentation/parts&mode=overwrite&failonwarnings=true
Host: apigateway.region
.amazonaws.com
Content-Type: application/json
X-Amz-Date: YYYYMMDDTttttttZ
Authorization: AWS4-HMAC-SHA256 Credential=access_key_id
/YYYYMMDD
/region
/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=sigv4_secret
{
"openapi": "3.0.0",
"info": {
"description": "description",
"version": "1",
"title": "doc"
},
"paths": {
"/": {
"get": {
"description": "Method description.",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Empty"
}
}
}
}
}
}
}
},
"x-amazon-apigateway-documentation": {
"version": "1.0.3",
"documentationParts": [
{
"location": {
"type": "API"
},
"properties": {
"description": "API description",
"info": {
"description": "API info description 4",
"version": "API info version 3"
}
}
},
{
"location": {
"type": "METHOD",
"method": "GET"
},
"properties": {
"description": "Method description."
}
},
{
"location": {
"type": "MODEL",
"name": "Empty"
},
"properties": {
"title": "Empty Schema"
}
},
{
"location": {
"type": "RESPONSE",
"method": "GET",
"statusCode": "200"
},
"properties": {
"description": "200 response"
}
}
]
},
"servers": [
{
"url": "/"
}
],
"components": {
"schemas": {
"Empty": {
"type": "object",
"title": "Empty Schema"
}
}
}
}
- OpenAPI 2.0
-
PUT /restapis/<restapi_id>/documentation/parts&mode=overwrite&failonwarnings=true
Host: apigateway.region
.amazonaws.com
Content-Type: application/json
X-Amz-Date: YYYYMMDDTttttttZ
Authorization: AWS4-HMAC-SHA256 Credential=access_key_id
/YYYYMMDD
/region
/apigateway/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=sigv4_secret
{
"swagger": "2.0",
"info": {
"description": "description",
"version": "1",
"title": "doc"
},
"host": "",
"basePath": "/",
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"description": "Method description.",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/Empty"
}
}
}
}
}
},
"definitions": {
"Empty": {
"type": "object",
"title": "Empty Schema"
}
},
"x-amazon-apigateway-documentation": {
"version": "1.0.3",
"documentationParts": [
{
"location": {
"type": "API"
},
"properties": {
"description": "API description",
"info": {
"description": "API info description 4",
"version": "API info version 3"
}
}
},
{
"location": {
"type": "METHOD",
"method": "GET"
},
"properties": {
"description": "Method description."
}
},
{
"location": {
"type": "MODEL",
"name": "Empty"
},
"properties": {
"title": "Empty Schema"
}
},
{
"location": {
"type": "RESPONSE",
"method": "GET",
"statusCode": "200"
},
"properties": {
"description": "200 response"
}
}
]
}
}
成功時,此請求會傳回 200 OK 回應,其中包含承載中已匯入的 DocumentationPartId
。
{
"ids": [
"kg3mth",
"796rtf",
"zhek4p",
"5ukm9s"
]
}
此外,您還可以調用 restapi: import 或 restapi: put,提供x-amazon-apigateway-documentation
對象中的文檔部分作為定義的輸入打開文件的一部分。API API若要從API匯入中排除文件集零件,請ignore=documentation
在請求查詢參數中設定。
使用API閘道主控台匯入文件組件
下列說明示範如何匯入文件組件。