Importing APIs through an API Design File
You can import Swagger and OpenAPI APIs to a new or existing API group on APIG. Before importing APIs, complete the extended definition of APIG.
Precautions
- The API group and API quotas in API Gateway are sufficient.
- If you use the title property in Swagger info and OpenAPI info to specify an API group name, the name of a new API group cannot be the same as that of an existing one.
- If a conflict exists when you import APIs, the former API is imported successfully and the latter API cannot be imported. For example, if two APIs with the same name or request path exist in the imported API definition, a success message is displayed for the first imported API, and a failure message is displayed for the API to be imported subsequently.
- If the definition of an API you are importing is the same as that of an existing API, you can overwrite the existing API or retain it. If you leave the existing API alone, the new API will not be imported.
- If Extended Definition Overwrite is selected, the extended definition items (access control and request throttling policies) of an imported API will overwrite the existing extended definition items with the same name.
- Imported APIs will not be automatically published in an environment. You can choose to publish them immediately or later.
- Load balance channels of APIs cannot be imported.
Importing an API Design File
- Go to the APIG console.
- Select a dedicated gateway at the top of the navigation pane.
- APIs can be imported in the following path:
- In the navigation pane, choose API Management > API Groups. Choose Create API Group > Import API Design File.
- Choose API Management > APIs. Click Import APIs.
- Select an API file and click Open.
- Set the parameters according to the following table.
Table 1 Parameters for importing APIs Parameter
Description
Import
Options:
- New group: Import APIs to a new API group. If you select this option, the system automatically creates an API group and imports the APIs into this group.
- Existing group: Import APIs to an existing API group. If you select this option, the system adds the APIs to the selected API group while retaining the existing APIs in the API group.
API group
Select an API group if you set Import to Existing group.
Basic Definition Overwrite
Determine whether to overwrite an existing API if the name of the API is the same as that of an imported API.
This parameter is available only if you set Import to Existing group.
Extended Definition Overwrite
If this option is selected, the extended definition items (access control and request throttling policies) of an imported API will overwrite the existing policies with the same name.
- (Optional) To configure the APIs, click Configure Global Settings.
- Change the authentication mode. For details, see 5.b.
- Modify the backend request configuration. For details, see 1.
- Click Next. You can view the configuration details in form, JSON, or YAML format.
- Confirm the settings and click Submit.
- Click Import Now, and determine whether to publish the APIs.
- Now: Publish the APIs in a specified environment now.
- Later: Publish the APIs later.
- Click OK. The APIs tab is displayed, showing the imported APIs.
You can also import APIs to APIG by referring to the following examples:
- Importing an HTTP Backend Service API
- Importing an HTTP VPC Backend Service API
- Importing a Function Backend Service API
- Importing a Mock Backend Service API
Importing an HTTP Backend Service API
Import the request parameter definition of an HTTP backend service API that uses the GET method and is accessed through IAM authentication.
Swagger example:
swagger: "2.0"info:title: "importHttpEndpoint10"description: "import apis"version: "1.0"host: "api.account.com"paths:'/http/{userId}':get:operationId: "getUser3"description: "get user by userId"security:- apig-auth-iam: []schemes:- httpsparameters:- name: "test"description: "authorization token"type: "string"in: "header"required: true- name: "userId"description: "user id"type: "string"in: "path"required: trueresponses:"200":description: "user information"x-apigateway-request-type: "public"x-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: "NORMAL"x-apigateway-backend:type: "HTTP"parameters:- name: "userId"value: "userId"in: "query"origin: "REQUEST"description: "user id"- name: "X-Invoke-User"value: "apigateway"in: "header"origin: "CONSTANT"description: "invoke user"httpEndpoints:address: "example.com"scheme: "http"method: "GET"path: "/users"timeout: 30000securityDefinitions:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAM
OpenAPI example:
openapi: 3.0.0info:title: importHttpEndpoint10version: '1.0'servers:- url: >-http://abc.com- url: >-https://abc.compaths:'/http/{userId}':get:description: get user by userIdoperationId: getUser3parameters:- description: authorization tokenexample: ''in: headername: testrequired: trueschema:maxLength: 0maximum: 0minimum: 0type: stringx-apigateway-pass-through: always- description: user idexample: ''in: pathname: userIdrequired: trueschema:maxLength: 0maximum: 0minimum: 0type: stringx-apigateway-pass-through: alwaysresponses:default-cors:description: response examplex-apigateway-result-failure-sample: ''x-apigateway-result-normal-sample: ''security:- apig-auth-iam: []servers:- url: >-https://abc.comx-apigateway-backend:httpEndpoints:address: example.comdescription: ''enableClientSsl: falsemethod: GETpath: /usersretryCount: '-1'scheme: httptimeout: 30000parameters:- description: invoke userin: HEADERname: X-Invoke-Userorigin: CONSTANTvalue: apigateway- description: user idin: QUERYname: userIdorigin: REQUESTvalue: userIdtype: HTTPx-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: NORMALx-apigateway-request-type: publicx-apigateway-response: defaultcomponents:responses:default-cors:description: response exampleheaders:Access-Control-Allow-Origin:schema:default: '*'type: stringsecuritySchemes:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-app-header:in: headername: Authorizationtype: apiKeyx-apigateway-auth-opt:appcode-auth-type: headerx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAMx-apigateway-responses:default: {}
Importing an HTTP VPC Backend Service API
Import the request parameter definition of an HTTP VPC backend service API that uses the ANY method and is accessed through app authentication.
Swagger example:
swagger: "2.0"info:title: "importHttpVpcEndpoint"description: "import apis"version: "1.0"host: "api.account.com"paths:'/http-vpc':x-apigateway-any-method:operationId: "userOperation"description: "user operation resource"security:- apig-auth-app: []schemes:- httpsparameters:- name: "Authorization"description: "authorization signature"type: "string"in: "header"required: trueresponses:"default":description: "endpoint response"x-apigateway-request-type: "public"x-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: "SWA"x-apigateway-backend:type: "HTTP-VPC"parameters:- name: "X-Invoke-User"value: "apigateway"in: "header"origin: "CONSTANT"description: "invoke user"httpVpcEndpoints:name: "userVpc"scheme: "http"method: "GET"path: "/users"timeout: 30000securityDefinitions:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAM
OpenAPI example:
openapi: 3.0.0info:description: import apistitle: importHttpVpcEndpointversion: '1.0'servers:- url: >-http://abc.com- url: >-https://abc.compaths:/http-vpc:x-apigateway-any-method:description: user operation resourceoperationId: userOperationparameters:- description: authorization signatureexample: ''in: headername: Authorizationrequired: trueschema:maxLength: 0maximum: 0minimum: 0type: stringx-apigateway-pass-through: alwaysresponses:default-cors:description: response examplex-apigateway-result-failure-sample: ''x-apigateway-result-normal-sample: ''security:- apig-auth-app: []servers:- url: >-https://abc.comx-apigateway-backend:httpVpcEndpoints:cascade_flag: falsedescription: ''enableClientSsl: falsemethod: GETname: userVpcpath: /usersretryCount: '-1'scheme: httptimeout: 30000parameters:- description: invoke userin: HEADERname: X-Invoke-Userorigin: CONSTANTvalue: apigatewaytype: HTTP-VPCx-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: SWAx-apigateway-request-type: publiccomponents:responses:default-cors:description: response exampleheaders:Access-Control-Allow-Origin:schema:default: '*'type: stringsecuritySchemes:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-app-header:in: headername: Authorizationtype: apiKeyx-apigateway-auth-opt:appcode-auth-type: headerx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAMx-apigateway-responses: {}
Importing a Function Backend Service API
Import the request parameter definition of a FunctionGraph backend service API that uses the GET method and is accessed through IAM authentication.
Swagger example:
swagger: "2.0"info:title: "importFunctionEndpoint"description: "import apis"version: "1.0"host: "api.account.com"paths:'/function/{name}':get:operationId: "invokeFunction"description: "invoke function by name"security:- apig-auth-iam: []schemes:- httpsparameters:- name: "test"description: "authorization token"type: "string"in: "header"required: true- name: "name"description: "function name"type: "string"in: "path"required: trueresponses:"200":description: "function result"x-apigateway-request-type: "public"x-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: "NORMAL"x-apigateway-backend:type: "FUNCTION"parameters:- name: "functionName"value: "name"in: "query"origin: "REQUEST"description: "function name"- name: "X-Invoke-User"value: "apigateway"in: "header"origin: "CONSTANT"description: "invoke user"functionEndpoints:function-urn: "your function urn address"version: "your function version"invocation-type: "async"timeout: 30000securityDefinitions:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAM
OpenAPI example:
openapi: 3.0.0info:description: import apistitle: importHttpEndpointversion: '1.0'servers:- url: >-http://api.account.com- url: >-https://api.account.compaths:/function/{name}:get:description: invoke function by nameoperationId: invokeFunctionparameters:- description: function namein: pathname: namerequired: trueschema:maxLength: 0maximum: 0minimum: 0type: stringx-apigateway-pass-through: alwaysexample: ''- description: authorization tokenin: headername: testrequired: trueschema:maxLength: 0maximum: 0minimum: 0type: stringx-apigateway-pass-through: alwaysexample: ''responses:default-cors:description: response examplex-apigateway-result-failure-sample: ''x-apigateway-result-normal-sample: ''security:- apig-auth-iam: []servers:- url: >-https://api.account.comx-apigateway-backend:functionEndpoints:alias-urn: ''description: ''function-urn: "your function urn address"invocation-type: asyncnetwork-type: V1timeout: 30000version: "your function version"parameters:- description: invoke userin: HEADERname: X-Invoke-Userorigin: CONSTANTvalue: apigateway- description: function namein: QUERYname: functionNameorigin: REQUESTvalue: nametype: FUNCTIONx-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: NORMALx-apigateway-request-type: publicx-apigateway-response: defaultcomponents:responses:default-cors:description: response exampleheaders:Access-Control-Allow-Origin:schema:default: '*'type: stringsecuritySchemes:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAMx-apigateway-responses:default: {}
Importing a Mock Backend Service API
Import the definition of a Mock backend service API that uses the GET method and is accessed without authentication.
Swagger example:
swagger: "2.0"info:title: "importMockEndpoint"description: "import apis"version: "1.0"host: "api.account.com"paths:'/mock':get:operationId: "mock"description: "mock test"schemes:- httpresponses:"200":description: "mock result"x-apigateway-request-type: "private"x-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: "NORMAL"x-apigateway-backend:type: "MOCK"mockEndpoints:result-content: "{\"message\": \"mocked\"}"securityDefinitions:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAM
OpenAPI example:
openapi: 3.0.0info:description: import apistitle: importHttpVpcEndpointversion: '1.0'servers:- url: >-http://abc.com- url: >-https://abc.compaths:/mock:get:description: mock testoperationId: mockresponses:default-cors:description: response examplex-apigateway-result-failure-sample: ''x-apigateway-result-normal-sample: ''servers:- url: >-http://abc.comx-apigateway-backend:mockEndpoints:description: ''result-content: '{"message": "mocked"}'type: MOCKx-apigateway-cors: truex-apigateway-is-send-fg-body-base64: truex-apigateway-match-mode: NORMALx-apigateway-request-type: privatex-apigateway-response: defaultcomponents:responses:default-cors:description: response exampleheaders:Access-Control-Allow-Origin:schema:default: '*'type: stringsecuritySchemes:apig-auth-app:in: headername: Authorizationtype: apiKeyx-apigateway-auth-type: AppSigv1apig-auth-app-header:in: headername: Authorizationtype: apiKeyx-apigateway-auth-opt:appcode-auth-type: headerx-apigateway-auth-type: AppSigv1apig-auth-iam:in: headername: unusedtype: apiKeyx-apigateway-auth-type: IAMx-apigateway-responses:default: {}
Follow-Up Operations
Publish the imported APIs in an environment so that they can be called by users.
- Precautions
- Importing an API Design File
- Importing an HTTP Backend Service API
- Importing an HTTP VPC Backend Service API
- Importing a Function Backend Service API
- Importing a Mock Backend Service API
- Follow-Up Operations