Using Design By Example to Infer Parameter Data Types
Design by example is a feature that provides automated inference of the definition set (XML schema) based on the response from the REST data sources. After you create your REST data source, you can open the data source editor and infer the data types of the parameters by using the Design By Example button, and then you can edit the type if necessary. Typically, design by example is used to infer the data type of body parameters.
There are several ways to access the design by example functionality, including:
Creating a Definition Set by Example Using the Data Source Editor
Whether you are creating a new REST data source or editing an existing one, the way you interact with the editor to gain access to the design by example feature is the same.
To create a definition set by example from the Data Source editor
Make sure that all the input parameters defined for your REST data source are defined according to REST operation requirements.
Because the definition set is created from the REST service response, correct input is important, so that the response is correct.
|
2.
|
Make sure that the following is true for the data source: |
|
—
|
Operations have been assigned HTTP verbs. |
|
—
|
If the Operation URL includes a variable, it is in curly brackets ({}). The URL parameters must be parsed and listed in the URL Parameters portion of the screen. |
|
—
|
It has been saved and introspected. |
|
3.
|
Open the REST data source editor if it is not already open. |
|
4.
|
Select the Configuration tab. |
|
5.
|
Scroll down to the Connection Information portion of the tab and select the Basic tab. |
|
6.
|
Scroll down to the Operations portion of the screen. |
|
7.
|
Under the Header/Body Parameters portion of the screen, click Design By Example. |
If an XML schema file was previously created or specified for this data source, a message pops up. Click OK to continue and overwrite that file with the new information.
|
8.
|
If your operation has input parameters, type values for the URL Parameters in the Input Values for <op_variable> window. The value that you type must be consistent with the data type of the URL parameter. |
The Add Definition Type dialog appears.
|
9.
|
In the tree pane of the screen, navigate to a sample definition set. TDV uses the sample definition set to automatically create a new definition set from the JSON or XML responses for your REST operation. After the definition set has been created, you can edit it. |
Typically, design by example logic is used to suggest metadata for body parameter types, which are usually OUT parameters.
|
10.
|
In the right-side pane, select an Element or Type from the definition set for the Show field, and then select one of the values in the list in the other portion of the screen. |
After you make a selection, the full Studio tree path to that sample definition appears in the Type field.
A new row appears in the Header/Body Parameters section with no name, but with default location (Body), data type, and in/out direction (IN). A new definition set resource is created in Studio under the REST data source with the name of the operation TDV used to suggest the schema.
|
12.
|
Double-click under Param Name and type the name of the parameter. |
|
13.
|
Validate that the values listed for the other columns are consistent with your design. |
|
14.
|
For JSON formatted data, make your XML <-> JSON choice. Select the check box to convert the result set to XML. Clear the check box to retain the JSON formatting. |
|
15.
|
Save your edited data source. |
Creating a Definition Set by Example Using a Web Service Operation Editor
To create a definition set by example from a Web service operation editor
Make sure that all the input parameters defined for your REST data source are defined according to REST operation requirements.
Because the definition set will be created from the REST service response, only correct input of the request could get correct response back.
|
17.
|
Make sure that the following is true for the data source: |
|
—
|
Operations have been assigned HTTP verbs. |
|
—
|
If the Operation URL includes a variable, it is in curly brackets ({}), and the URL parameters are parsed and listed in the URL Parameters portion of the screen. |
|
—
|
It has been saved and introspected. |
|
18.
|
From the Studio resource tree, expand the REST data source node. |
|
19.
|
Select an operation and open its editor. |
|
20.
|
Click Design By Example. |
If an XML schema file was previously created or specified for this data source, a message pops up. Click OK to continue and overwrite that file with the new information.
|
21.
|
If your operation has input parameters, type values for the URL Parameters in the Input Values for <op_variable> window. The value that you type must be consistent with the data type of the URL parameter. |
The Add Definition Type dialog appears.
|
22.
|
In the tree pane of the screen, navigate to a sample definition set. TDV uses the sample definition set to automatically create a new definition set from the JSON or XML responses to the REST operation. After the definition set has been created, you can edit it. |
Typically, design by example logic is used to suggest metadata for Body parameter types, which are usually OUT parameters.
|
23.
|
In the right-side pane, select an Element or Type from the definition set for the Show field, and then select one of the values in the list in the other portion of the screen. |
After you make a selection, the full Studio tree path to that sample definition appears in the Type field.
A new row appears in the Header/Body Parameters section with no name, but with default location (Body), data type, and in/out direction (IN). A new definition set resource is created in Studio under the REST data source with the name of the operation TDV used to suggest the schema.
|
25.
|
Double-click under Param Name and type the name of the parameter. |
|
26.
|
Validate that the values listed for the other columns are consistent with your design. |