You can export APIs from an API group in OAS 2.0 or OAS 3.0 format to migrate APIs across accounts, regions, or platforms.
Overview
You can export APIs from API Gateway in OAS format. Combined with the API import feature, this enables the following scenarios. For more information about the API import feature, see Import OAS-compliant APIs.
-
Migrate APIs across accounts, regions, or platforms: Export OAS-compliant APIs from API Gateway or another platform, and then import them into a different Alibaba Cloud account, region, or platform.
-
Publish and extend APIs: Convert OAS-compliant API definitions into API resources in API Gateway to quickly create and configure APIs, then customize their behavior as needed. API Gateway helps you manage access permissions, throttle traffic, and forward requests securely.
-
Integrate and collaborate: Integrate exported APIs with other development tools or platforms based on the OAS standard. Sharing API definitions reduces communication overhead and development effort across teams.
Export OAS-compliant APIs
You can export an entire API group or specific APIs.
Procedure
-
Export an API group
-
Log on to the API Gateway console.
-
In the left-side navigation pane, choose Manage APIs > API Groups.
-
On the API Groups page, find the API group that you want to export. Click
and then choose Export API Definitions in the Actions column. -
In the Export API Definitions dialog box, specify the Data Format, Stage, and Export Extended Definitions parameters. Then, click Confirm.
-
-
Export specific APIs
-
Log on to the API Gateway console.
-
In the left-side navigation pane, choose Manage APIs > APIs.
-
On the APIs page, select the APIs that you want to export and choose More > Export API Definitions below the list.
-
In the Export API Definitions dialog box, specify the Data Format, Stage, and Export Extended Definitions parameters. Then, click Confirm.
-
Extended API definitions
If you select Yes for the Export Extended Definitions parameter, the following API Gateway-specific fields are added to the exported files.
|
Extended field |
Location in OAS 2.0 |
Location in OAS 3.0 |
Description |
Type |
Valid values |
|
x-aliyun-apigateway-any-method |
Paths Object |
Paths Object |
The complete definition of the ANY method. |
Object |
- |
|
x-aliyun-apigateway-backend |
Operation Object |
Operation Object |
The backend service. |
Object |
- |
|
x-aliyun-apigateway-api-market-enable |
Operation Object |
Operation Object |
Specifies whether to allow the API to be published to Alibaba Cloud Marketplace. |
Boolean |
|
|
x-aliyun-apigateway-api-force-nonce-check |
Operation Object |
Operation Object |
Specifies whether to enable anti-replay protection. |
Boolean |
|
|
x-aliyun-apigateway-parameter-handling |
Operation Object |
Operation Object |
The request mode in the request definition. |
String |
|
|
x-aliyun-apigateway-auth-type |
Operation Object |
Operation Object |
The security authentication type. |
String |
|
|
x-aliyun-apigateway-app-code-type |
Operation Object |
Operation Object |
The AppCode authentication type. |
String |
|
|
x-aliyun-apigateway-constant-parameters |
Operation Object |
Operation Object |
The constant parameter definitions. |
Object |
- |
|
x-aliyun-apigateway-system-parameters |
Operation Object |
Operation Object |
The system parameter definitions. |
Object |
- |
|
x-aliyun-apigateway-api-enable-internet |
Operation Object |
Operation Object |
Specifies whether to allow access over the Internet. |
Boolean |
|
|
x-aliyun-apigateway-success-demo |
Operation Object |
Operation Object |
The sample return for a successful call. |
String |
- |
|
x-aliyun-apigateway-failed-demo |
Operation Object |
Operation Object |
The sample return for a failed call. |
String |
- |
|
x-aliyun-apigateway-api-name |
Operation Object |
Operation Object |
The API name. |
String |
- |
|
x-aliyun-apigateway-request-scheme |
N/A |
Operation Object |
The protocols that are supported by the API, such as HTTP. |
String |
- |
|
x-aliyun-apigateway-backend-location |
Parameter Object |
Parameter Object |
The mapped parameter locations in the backend service. |
String |
|
|
x-aliyun-apigateway-backend-name |
Parameter Object |
Parameter Object |
The mapped parameter names in the backend service. |
String |
- |
|
x-aliyun-apigateway-parameter-demo |
Parameter Object |
Parameter Object |
The sample parameter values. |
String |
- |
|
x-aliyun-apigateway-response-messages |
Responses Object |
Responses Object |
The error messages in the error definitions. |
String |
- |
Description
-
If you export by group, the base path of the group is exported.
-
You can export up to 300 APIs at a time. If the group to be exported contains more than 300 APIs, the first 300 APIs are exported.
-
If the model definition of an API group cannot be parsed, the model definition is not exported.
-
If you export specific APIs, all selected APIs are exported to the same file.
-
If APIs have the same path and method, only one of the APIs is exported.
-
If you select No for the Export Extended Definitions parameter, the OperationId value in the exported file is a concatenated string of the request path and request method of the API definition, such as export1ByGET.
-
If you select Yes for the Export Extended Definitions parameter, the additional information about the API, such as its bound plug-in, authorized application, bound domain name of the API group, and backend service definitions in different environments, is not exported.
Example
The following example shows an exported API group with extended API definitions.
swagger: '2.0'
info:
description: Export from api group xxx
version: 1.0.0
title: Api Gateway API
basePath: /export
paths:
/export1/{pathParam}:
get:
summary: test export job 1.
operationId: export1pathParamByGET
schemes:
- http
- https
parameters:
- name: pathParam
in: path
description: the path parameter.
required: true
type: string
maxLength: 10
x-aliyun-apigateway-parameter-demo: pathValue
x-aliyun-apigateway-backend-name: pathParam
x-aliyun-apigateway-backend-location: path
- name: headParam
in: header
description: the header parameters.
required: false
type: string
x-aliyun-apigateway-parameter-demo: headerValue
x-aliyun-apigateway-backend-name: headParam
x-aliyun-apigateway-backend-location: query
- name: queryParam
in: query
description: the query parameters.
required: false
type: string
x-aliyun-apigateway-parameter-demo: queryValue
x-aliyun-apigateway-backend-name: queryParam
x-aliyun-apigateway-backend-location: header
responses:
'200':
description: success.
x-aliyun-apigateway-response-messages: success
'400':
description: client error.
x-aliyun-apigateway-response-messages: clent error
'500':
description: server error.
x-aliyun-apigateway-response-messages: server error
x-aliyun-apigateway-system-parameters:
- backendName: testClientIp
systemName: CaClientIp
location: header
x-aliyun-apigateway-constant-parameters:
- backendName: constantparam
location: header
value: constantValue
descriptoin: the constant parameters.
x-aliyun-apigateway-api-name: export_1
x-aliyun-apigateway-api-market-enable: false
x-aliyun-apigateway-api-force-nonce-check: true
x-aliyun-apigateway-parameter-handling: MAPPING
x-aliyun-apigateway-auth-type: APP
x-aliyun-apigateway-api-enable-internet: true
x-aliyun-apigateway-failed-demo: '{"result":"fail"}'
x-aliyun-apigateway-success-demo: '{"result":"success"}'
x-aliyun-apigateway-app-code-type: DEFAULT
x-aliyun-apigateway-backend:
body: good job
statusCode: 200
header:
- name: test
value: header1
type: MOCK
/export2/*:
x-aliyun-apigateway-any-method:
operationId: export_2
description: test export job 1.
x-aliyun-apigateway-api-market-enable: false
x-aliyun-apigateway-api-force-nonce-check: false
x-aliyun-apigateway-api-enable-internet: true
x-aliyun-apigateway-parameter-handling: PASSTHROUGH
x-aliyun-apigateway-auth-type: ANONYMOUS
x-aliyun-apigateway-success-demo: '{"result":"success"}'
x-aliyun-apigateway-failed-demo: '{"result":"fail"}'
schemes:
- http
- https
x-aliyun-apigateway-backend:
body: good job
statusCode: 200
header:
- name: test
value: header1
type: MOCK
x-aliyun-apigateway-constant-parameters:
- backendName: constantparam
location: header
value: constantValue
descriptoin: the constant parameters.
x-aliyun-apigateway-system-parameters:
- backendName: testClientIp
systemName: CaClientIp
location: header
responses:
'200':
description: success.
briefMessage: success
schema:
$ref: testModel
'400':
description: client error.
briefMessage: clent error
schema:
$ref: testModel
'500':
description: server error.
briefMessage: server error
definitions:
testModel:
type: object
required:
- name
properties:
dogProject:
type: object
properties:
name:
type: string
maxLength: 10
id:
type: integer
format: int64
name:
type: string
pattern: ^\d{3}-\d{2}-\d{4}$
id:
type: integer
format: int64
status:
type: string