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 extensions, in the exported OpenAPI definition file.
NoteWhen 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.
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:
https://<host>
/restapis/<restapi_id>
/stages/<stage_name>
/exports/oas30
https://<host>
/restapis/<restapi_id>
/stages/<stage_name>
/exports/swagger
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.
NoteIf 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 JSONTo export and download a REST API in OpenAPI definitions in JSON format:
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/oas30
Host: apigateway.<region>
.amazonaws.com
Accept: application/json
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/swagger
Host: apigateway.<region>
.amazonaws.com
Accept: application/json
Here,
could be, for example, <region>
us-east-1
. For all the regions where API Gateway is available, see Regions and Endpoints.
To export and download a REST API in OpenAPI definitions in YAML format:
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/oas30
Host: apigateway.<region>
.amazonaws.com
Accept: application/yaml
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/swagger
Host: apigateway.<region>
.amazonaws.com
Accept: application/yaml
To export and download a REST API in OpenAPI definitions with Postman in JSON format:
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/oas30?extensions=postman
Host: apigateway.<region>
.amazonaws.com
Accept: application/json
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/swagger?extensions=postman
Host: apigateway.<region>
.amazonaws.com
Accept: application/json
To export and download a REST API in OpenAPI definitions with API Gateway integration in YAML format:
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/oas30?extensions=integrations
Host: apigateway.<region>
.amazonaws.com
Accept: application/yaml
GET /restapis/<restapi_id>
/stages/<stage_name>
/exports/swagger?extensions=integrations
Host: apigateway.<region>
.amazonaws.com
Accept: application/yaml
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4