Import a data model
API Gateway helps you quickly create data models by allowing you to import them from Proto and Swagger files.
Procedure
Log on to the API Gateway console.
In the navigation pane on the left, click API Publishing > Data Models.
In the upper-right corner of the page, click Import Data Model. In the dialog box that appears, configure the data model information.
Select import type: API Gateway supports importing data models from Swagger and ProtoBuf. Select a type based on your business needs.
Swagger model: Swagger is a specification and a complete framework for generating, describing, calling, and visualizing RESTful web services.
ProtoBuf model: ProtoBuf is an open source tool for structured information exchange. It is used in scenarios such as data storage and transport protocol formatting.
Import method:
URL: Enter the URL of the Swagger configuration. API Gateway parses the remote data model and uploads it to the platform.
FILE: After you select an import type, click Upload File. You can upload a Swagger 2.0 or 3.0 file in json or yaml format.
Performance optimization:
NoteA model name is not required for ProtoBuf and Swagger imports.
API Gateway parses parameter names, structures, and types from the Model in a Swagger 2.0 file or the Schema in a Swagger 3.0 file. The service then transforms this information and imports it as a data model. This data model lets you automatically generate a sample JSON for request parameters in an API. You can also use the data model directly in flow orchestration for tasks such as parameter settings and parameter mapping.
Click OK to complete the import.
After the data model is imported, you can select and bind it when you configure request or response parameters for an API.
Other operations
Generate an SDK
API Gateway lets you download an SDK to simplify API calls and reduce repetitive coding. You can also provide the SDK to external users.
API Gateway supports downloading SDKs at the group and application levels. The following procedure uses a group as an example.
Log on to the API Gateway console.
In the navigation pane on the left, click API Publishing > API Groups.
Click Download SDK on the right of the group list.
On the group details page, configure the parameters for the SDK download.
Package Name: Required. The package name for the generated classes.
Code Language: The programming language for the SDK. Currently, only Java is supported.
Click Download to generate the SDK.
NoteThe SDK is downloaded as a ZIP file. You can import the Java class files from the ZIP package into your project.
Notes
Unsupported Data Types for Gateway SDK Generation
Container types with multiple levels of nesting are not supported.
List or Map types must specify their generic types.
The generic type for a List or Map cannot be an Array.
Single bytes are not supported. However, byte arrays (byte[]) are supported.
Object arrays are not supported. Use a List instead.
Property names cannot be
dataordescriptionbecause this conflicts with iOS properties.The key for a Map type must be a String.
The value for a Map type cannot be an Object.
The type cannot be an abstract class.
The type cannot be an interface class.
Incorrect example:
public class Req {
private Map<String,List<Person>> map; // Container types cannot have multiple levels of nesting.
private List<Map<Person>> list; // Container types cannot have multiple levels of nesting.
private List list1; // List or Map must have generic information.
private Map map1; // List or Map must have generic information.
private List<Person[]> listArray; // The generic type for a List or Map cannot be an Array.
private byte b; // Single bytes are not supported.
private Person[] personArray; // Object arrays are not supported. Use a List instead.
private String description; // The property name cannot be description.
}Data types supported for SDK generation
boolean, double, float, int, long, short
java.lang.Boolean
java.lang.Double
java.lang.Float
java.lang.Integer
java.lang.Long
java.lang.Short
java.lang.String
java.util.List: You must use type parameters. You cannot use its specific child classes.
java.util.Map: You must use type parameters, and you cannot use its specific child classes. The key type must be a String.
Enum
byte[]Correct example:
public class Req {
private String s = "ss";
private int i;
private double d;
private Long l;
private long l1;
private boolean b;
private List<String> stringList;
private List<Person> personList;
private Map<String,Person> map;
private byte[] bytes;
private EnumType type;
}
public class Person {
private String name;
private int age;
}