更新时间:2026-08-13 GMT+08:00
APIG
API网关(APIG)是为企业和开发者提供的高性能、高可用、高安全的云原生网关服务,帮助企业快速构建、管理和部署API。当网关Target配置为APIG类型时,将以APIG上注册的API作为目标服务。此时,需从APIG导出API文档,并补充完善请求体的详细定义后,方可调用后端服务。
约束与限制
- 仅支持OpenAPI 3.0 和Swagger 2.0 规范。
APIG类型的Target请求体配置示例
补充请求体的详细定义:
- 修改前(导出默认):schema 为 "type": "object",无具体字段定义。 图2 修改前
- 修改后(所需配置):将 "type": "object" 替换为 "$ref": "#/components/schemas/Pet",并在 components 中新增 schemas 节点定义具体结构。 图3 修改后的请求体
图4 新增schemas节点具体结构
导出的原始 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"
}
}
}
} 父主题: 支持的Target类型

