
# APIG
API网关（APIG）是为企业和开发者提供的高性能、高可用、高安全的云原生网关服务，帮助企业快速构建、管理和部署API。当网关Target配置为APIG类型时，将以APIG上注册的API作为目标服务。此时，需从APIG导出API文档，并补充完善请求体的详细定义后，方可调用后端服务。
#### 约束与限制
- 仅支持OpenAPI 3.0 和Swagger 2.0 规范。

- 响应体需用户自行配置，且必须使用$ref引用方式定义。
- 当网关出网配置为公网访问时，APIG实例需开启公网入口；当网关出网配置为私网访问时，所配置的VPC需与APIG实例所在VPC网络互通。
- 出站认证支持IAM以及无认证方式。 使用IAM出站认证时，需确保创建的出站身份认证中，IAM信任委托包含如下 Action 权限：
  sts::setContext：获取STS5委托需要的权限，用于获取临时凭据时携带用户的WAT信息。
  ![](https://support.huaweicloud.com/highcode-agentarts/zh-cn_image_0000002681881575.png)
  
 
 #### APIG类型的Target请求体配置示例
参考[图1]，[导出APIG的API](https://support.huaweicloud.com/usermanual-apig/apig_03_0015.html)，从导出的API定义中，请求体（requestBody）为通用的object类型，无法被网关准确解析，需补充请求体的详细定义。
图1导出API   
![](https://support.huaweicloud.com/highcode-agentarts/zh-cn_image_0000002651682076.png "点击放大")
**补充请求体的详细定义：**
- 修改前（导出默认）：schema 为 "type": "object"，无具体字段定义。
  图2修改前   
  ![](https://support.huaweicloud.com/highcode-agentarts/zh-cn_image_0000002651841966.png "点击放大") 
- 修改后（所需配置）：将 "type": "object" 替换为 "$ref": "#/components/schemas/Pet"，并在 components 中新增 schemas 节点定义具体结构。
  图3修改后的请求体   
  ![](https://support.huaweicloud.com/highcode-agentarts/zh-cn_image_0000002681721777.png "点击放大")
  图4新增schemas节点具体结构   
  ![](https://support.huaweicloud.com/highcode-agentarts/zh-cn_image_0000002681881607.png "点击放大")
  
  
**导出的原始 API 示例：**
```
{
    "openapi": "3.0.3",
    "info": {
        "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we have switched to the design first approach!\nYou can now",
        "title": "Petstore",
        "version": "2026-07-16-09:51:07"
    },
    "servers": [
        {
            "url": "https://gateway-test.cn-north-7.myhuaweicloud.com"
        }
    ],
    "paths": {
        "/pet": {
            "post": {
                "description": "Add a new pet to the store.",
                "operationId": "addPet",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "example": "",
                                "type": "object"    #【修改点1】：此处需替换为具体的 $ref 引用
                            }
                        }
                    }
                },
                "responses": {
                    "default": {
                        "description": "response example",
                        "x-apigateway-result-failure-sample": "",
                        "x-apigateway-result-normal-sample": ""
                    }
                },
                "security": [
                    {
                        "apig-auth-iam": []
                    }
                ],
                "servers": [
                    {
                        "url": "https://gateway-example.com"
                    }
                ],
                "tags": [
                    "pet"
                ],
                "x-apigateway-backend": {
                    "httpVpcEndpoints": {
                        "cascade_flag": false,
                        "description": "",
                        "enableClientSsl": false,
                        "enableSmChannel": false,
                        "method": "POST",
                        "name": "VPC_gjlc",
                        "path": "/pet",
                        "retryCount": "0",
                        "scheme": "http",
                        "timeout": 5000
                    },
                    "type": "HTTP-VPC"
                },
                "x-apigateway-cors": false,
                "x-apigateway-is-send-fg-body-base64": true,
                "x-apigateway-match-mode": "NORMAL",
                "x-apigateway-request-type": "public"
            },
            "put": {
                "description": "Update an existing pet by Id.",
                "operationId": "updatePet",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "example": "",
                                "type": "object"      #【修改点2】：此处需替换为具体的$ref 引用
                            }
                        }
                    }
                },
                "responses": {
                    "default": {
                        "description": "response example",
                        "x-apigateway-result-failure-sample": "",
                        "x-apigateway-result-normal-sample": ""
                    }
                },
                "servers": [
                    {
                        "url": "https://gateway-example.com"
                    }
                ],
                "tags": [
                    "pet"
                ],
                "x-apigateway-backend": {
                    "httpVpcEndpoints": {
                        "cascade_flag": false,
                        "description": "",
                        "enableClientSsl": false,
                        "enableSmChannel": false,
                        "method": "PUT",
                        "name": "VPC_gjlc",
                        "path": "/pet",
                        "retryCount": "0",
                        "scheme": "http",
                        "timeout": 5000
                    },
                    "type": "HTTP-VPC"
                },
                "x-apigateway-cors": false,
                "x-apigateway-is-send-fg-body-base64": true,
                "x-apigateway-match-mode": "NORMAL",
                "x-apigateway-request-type": "public"
            }
        }
    },
    "components": {
        "responses": {
            "default": {
                "description": "response example"
            }
        },
        "securitySchemes": {       #【修改点3】：补充 schemas 定义
            "apig-auth-app": {
                "in": "header",
                "name": "Authorization",
                "type": "apiKey",
                "x-apigateway-auth-type": "AppSigv1"
            },
            "apig-auth-app-header": {
                "in": "header",
                "name": "Authorization",
                "type": "apiKey",
                "x-apigateway-auth-opt": {
                    "appcode-auth-type": "header"
                },
                "x-apigateway-auth-type": "AppSigv1"
            },
            "apig-auth-iam": {
                "in": "header",
                "name": "unused",
                "type": "apiKey",
                "x-apigateway-auth-type": "IAM"
            }
        }
    }
}
```
**修改后的 API 示例：**
修改后的完整配置如下，重点关注requestBody和components.schemas的变化：
```
{
"openapi": "3.0.3",
"info": {
"description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at [https://swagger.io](https://swagger.io). In the third iteration of the pet store, we have switched to the design first approach!\nYou can now",
"title": "Petstore",
"version": "2026-07-10-00:12:36"
},
"servers": [
{
"url": "https://gateway-test.cn-north-7.myhuaweicloud.com"
}
],
"paths": {
"/pet": {
"post": {
"description": "Add a new pet to the store.",
"operationId": "addPet",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"     #【已修改】：指向具体的 Schema
}
}
}
},
"responses": {
"default": {
"description": "response example",
"x-apigateway-result-failure-sample": "",
"x-apigateway-result-normal-sample": ""
}
},
"security": [
{
"apig-auth-iam": []
}
],
"servers": [
{
"url": "https://gateway-test.cn-north-7.myhuaweicloud.com"
}
],
"tags": [
"pet"
],
"x-apigateway-backend": {
"httpVpcEndpoints": {
"cascade_flag": false,
"description": "",
"enableClientSsl": false,
"enableSmChannel": false,
"method": "POST",
"name": "VPC_4ap5",
"path": "/pet",
"retryCount": "0",
"scheme": "http",
"timeout": 5000
},
"type": "HTTP-VPC"
},
"x-apigateway-cors": false,
"x-apigateway-is-send-fg-body-base64": true,
"x-apigateway-match-mode": "NORMAL",
"x-apigateway-request-type": "public"
},
"put": {
"description": "Update an existing pet by Id.",
"operationId": "updatePet",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"    #【已修改】：指向具体的 Schema
}
}
}
},
"responses": {
"default": {
"description": "response example",
"x-apigateway-result-failure-sample": "",
"x-apigateway-result-normal-sample": ""
}
},
"security": [
{
"apig-auth-iam": []
}
],
"servers": [
{
"url": "https://gateway-test.cn-north-7.myhuaweicloud.com"
}
],
"tags": [
"pet"
],
"x-apigateway-backend": {
"httpVpcEndpoints": {
"cascade_flag": false,
"description": "",
"enableClientSsl": false,
"enableSmChannel": false,
"method": "PUT",
"name": "VPC_4ap5",
"path": "/pet",
"retryCount": "0",
"scheme": "http",
"timeout": 5000
},
"type": "HTTP-VPC"
},
"x-apigateway-cors": false,
"x-apigateway-is-send-fg-body-base64": true,
"x-apigateway-match-mode": "NORMAL",
"x-apigateway-request-type": "public"
}
}
},
"components": {
"responses": {
"default": {
"description": "response example"
}
},
"schemas": {                  # 【已新增】：补充具体的 Schema 定义
"Pet": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"category": {
"$ref": "#/components/schemas/Category"
},
"photoUrls": {
"type": "array",
"items": {
"type": "string"
}
},
"tags": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Tag"
}
},
"status": {
"type": "string",
"enum": [
"available",
"pending",
"sold"
]
}
},
"required": [
"name",
"photoUrls"
]
},
"Category": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
},
"Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
}
}
}
},
"securitySchemes": {
"apig-auth-app": {
"in": "header",
"name": "Authorization",
"type": "apiKey",
"x-apigateway-auth-type": "AppSigv1"
},
"apig-auth-app-header": {
"in": "header",
"name": "Authorization",
"type": "apiKey",
"x-apigateway-auth-opt": {
"appcode-auth-type": "header"
},
"x-apigateway-auth-type": "AppSigv1"
},
"apig-auth-iam": {
"in": "header",
"name": "unused",
"type": "apiKey",
"x-apigateway-auth-type": "IAM"
}
}
}
}
```
