Export a REST API from API Gateway
Once you created and configured a REST API in API Gateway, using the API Gateway console or
otherwise, you can export it to an OpenAPI file using the API Gateway Export API, which is part
of the Amazon API Gateway Control Service. To use the API Gateway Export API, you need to sign your API requests. For more information about signing requests, see Signing AWS API requests in the IAM User Guide. You have options to include the API Gateway
integration extensions, as well as the Postman
Note
When exporting the API using the AWS CLI, be sure to include the extensions parameter as shown in the following example, to ensure that the x-amazon-apigateway-request-validator
extension is included:
aws apigateway get-export --parameters extensions='apigateway' --rest-api-id abcdefg123 --stage-name dev --export-type swagger latestswagger2.json
You cannot export an API if its payloads are not of the application/json
type. If you try, you will get an error response stating that JSON body models are not found.
Request to export a REST API
With the Export API, you export an existing REST API by submitting a GET request, specifying the to-be-exported API as part of URL paths. The request URL is of the following format:
You can append the extensions
query string to specify whether to
include API Gateway extensions (with the integration
value) or Postman
extensions (with the postman
value).
In addition, you can set the Accept
header to
application/json
or application/yaml
to receive the
API definition output in JSON or YAML format, respectively.
For more information about submitting GET requests using the API Gateway Export API, see GetExport.
Note
If you define models in your API, they must be for the content type of "application/json" for API Gateway to export the model. Otherwise, API Gateway throws an exception with the "Only found non-JSON body models for ..." error message.
Models must contain properties or be defined as a particular JSONSchema type.
Download REST API OpenAPI definition in JSON
To export and download a REST API in OpenAPI definitions in JSON format:
Here,
could be, for
example, <region>
us-east-1
. For all the regions where API Gateway is available, see
Regions and Endpoints.
Download REST API OpenAPI definition in YAML
To export and download a REST API in OpenAPI definitions in YAML format:
Download REST API OpenAPI definition with Postman extensions in JSON
To export and download a REST API in OpenAPI definitions with Postman in JSON format:
Download REST API OpenAPI definition with API Gateway integration in YAML
To export and download a REST API in OpenAPI definitions with API Gateway integration in YAML format:
Export REST API using the API Gateway console
After deploying your REST API to a stage, you can proceed to export the API in the stage to an OpenAPI file using the API Gateway console.
In the Stages pane in the API Gateway console, choose Stage actions, Export.
Specify an API specification type, Format, and Extensions to download your API's OpenAPI definition.