All Products
Search
Document Center

Create APIs By Importing Swagger

Last Updated: Sep 11, 2018

Description

You can call this operation to import a Swagger API from a text string. It supports API configurations that comply with the following specifications:

  • Swagger 2.0-based extensions.
  • JSON or YAML format.

Request parameters

Name Type Required Description
Action String Yes You can call this operation to import Swagger APIs. Value: ImportSwagger.
GroupId String Yes The group number of the imported Swagger.
Overwrite Boolean Yes Specifies whether to overwrite the existing API. If the imported API has the same HTTP request method and request path as the existing API, the existing API will be overwritten.
DataFormat String Yes Swagger text format:
  • JSON
  • YAML
Data String Yes Swagger text content. For more information, see Import API through Swagger

Response parameters

Name Data type Description
RequestId String The request number.
Success ApiImportSwaggerSuccess Information about all Swagger-based APIs that have been successfully imported.
Failed ApiImportSwaggerFailed Information about all Swagger-based APIs that have failed to be imported.

Object description:

ApiImportSwaggerSuccess

Property name Data type Description
Path String The request path that is configured when you create an API.
Method String The configured HTTP method when you create an API.
ApiUid String The successfully imported UID for the API.
ApiOperation String Indicates whether a new API is created or an existing API is updated.

ApiImportSwaggerFailed

Property name Data type Description
Path String The request path that is configured when you create an API.
Method String The HTTP method that is configured when you create an API.
ErrorMsg String The error message that is returned when you create an API.

Sample requests

  1. POST /? Action=ImportSwagger
  2. &GroupId=0009db9c828549768a200320714b8930
  3. &Overwrite=true
  4. &DataFormat=yaml
  5. &Data="A Swagger API definition in YAML"
  6. &<Common request parameters>

Sample responses

XML format

  1. <RequestId>647CEF05-404C-4125-B3D7-44792EB77392</RequestId>
  2. <Failed>
  3. <ApiImportSwaggerFailed>
  4. <ErrorMsg>api already exists: apiUid ===&gt; 8e274ec61cf6468e83b68371956831cb</ErrorMsg>
  5. <HttpMethod>post</HttpMethod>
  6. <Path>/http/get/mapping</Path>
  7. </ApiImportSwaggerFailed>
  8. </Failed>
  9. <Success>
  10. <ApiImportSwaggerSuccess>
  11. <Operation>CREATE</Operation>
  12. <ApiUid>8e274ec61cf6468e83b68371956831cb</ApiUid>
  13. <HttpMethod>get</HttpMethod>
  14. <Path>/http/get/mapping</Path>
  15. </ApiImportSwaggerSuccess>
  16. </Success>

JSON format

  1. {
  2. "RequestId": "647CEF05-404C-4125-B3D7-44792EB77392",
  3. "Failed": {
  4. "ApiImportSwaggerFailed": [
  5. {
  6. "ErrorMsg": "api already exists : apiUid ===> 8e274ec61cf6468e83b68371956831cb",
  7. "HttpMethod": "post",
  8. "Path": "/http/get/mapping"
  9. }
  10. ]
  11. },
  12. "Success": {
  13. "ApiImportSwaggerSuccess": [
  14. {
  15. "Operation": "CREATE",
  16. "ApiUid": "8e274ec61cf6468e83b68371956831cb",
  17. "HttpMethod": "get",
  18. "Path": "/http/get/mapping"
  19. }
  20. ]
  21. }
  22. }