Defining Data Types

<< Click to Display Table of Contents >>

Navigation:  »No topics above this level«

Defining Data Types

Previous pageReturn to chapter overviewNext page

RepreZen™ API Studio uses a simple data definition language to define the structured data types used in our API.  These data types are technology-independent.  The RepreZen API Studio code generator will adapt them to the media types supported by our API.

Defining the first Data Type

The dataModel in our rapidModel currently contains a generated data structure called TaxBlaster. We'll rename and customize this now to suit our purposes:

1.First, we'll use code folding to fold the two generated resource definitions. This will make it easier to see what's going on. Press the little minus icons to the left of the objectResource and collectionResource elements so that they turn into little pluses, and the code looks like this:
 
DefineDataTypes_01
2.Next, we'll rename the TaxBlaster data type to something more useful. Find the word TaxBlaster just after the keyword structure in the dataModel and  press Alt+Shift+R to initiate a Rename refactoring operation:
 
DefineDataTypes_02
3.Type in the new name, TaxFiling, and press Enter to complete the refactoring.
Note: References to TaxFiling in the objectResource and collectionResource are also renamed to preserve consistency in the model:
 
DefineDataTypes_03
4.Now, we'll rename the id property of the generated structure to filingID using the same process:
 
DefineDataTypes_04
5.RepreZen API Studio data structures allow multiple, newline separated properties. We'll flesh out the TaxFiling structure now as follows:
 
structure TaxFiling
  filingID : string
  jurisdiction : string
  year : gYear
  period : int
  currency : string
  grossIncome : decimal
  taxLiability : decimal
 
DefineDataTypes_05

clip0007

Hint - Use Code Assist

As you are editing the model, you can get context-sensitive syntax help by pressing Ctrl+Space.  This opens a list of available code completions. You can use the mouse or the keyboard to navigate and select lines in the list.  Double-clicking or pressing Enter on a selected line in the list inserts the selection in the editor.

Defining a Person Data Type

Next, using a code assist template, we'll define another data type to describe a person associated with a tax filing as a taxpayer, dependent, or tax accountant.

1.Position the cursor on the bottom right-hand corner of the TaxFililing structure, press Enter and press Backspace once to put the cursor at the correct indent level for creating a new structure:
 
DefineDataTypes_06
2.Press Ctrl+Space to open Code Assist and find the structure template in the suggestion list.  This is the option at the bottom, with a green circle icon (indicating that this is a template):
 
DefineDataTypes_07
3.Double-click the structure template in the list (or select it with the keyboard and press Enter) to apply the template:
 
DefineDataTypes_08
4.The name of the new structure is highlighted. Overwrite this by typing Person and press Enter:
 
DefineDataTypes_09
5.Add the following properties to the Person structure:
 
id : string
lastName : string
firstName : string
otherNames : string*
 
DefineDataTypes_10
 
Note that the otherNames property has a data type of string*, with a star suffix.  This is the cardinality indicator.
6.Tax filings are made by, or on behalf of, taxpayers, so now we'll add another property to the TaxFiling data structure using the reference keyword to cover this. Insert a new line below the filingID property, press Ctrl+Space to open Code Assist, double-click reference property (or select it with the keyboard and press Enter):
 
DefineDataTypes_11
 

clip0007

Note: Optional Fluency

To aid fluency, and readability, the RAPID-ML™ language has optional keywords that may be used with normal keywords. (Optional keywords are denoted with a normal rather than a bold type face.) The reference keyword, for example, may be accompanied by the optional keywords as and to like this:

<name> as reference to <type>
or <name> reference to <type>.

You will see these different forms used in the guide.

7.Type taxpayer in the propertyName field, then press the tab key to move to the reference data type field. Note that a list of data types appears:
 
DefineDataTypes_12
8.Double-click Person, or use the keyboard to select it, and press Enter:
 
DefineDataTypes_13

Now we have defined the basic data model that our API will provide access to. In the next topic, we'll define resources bound to these data types.

Copyright © 2016 ModelSolv, Inc.  All rights reserved. RepreZen and RAPID-ML are trademarks of ModelSolv, Inc. Swagger is a registered trademark of SmartBear Software, Inc. RepreZen API Studio is not associated with nor endorsed by SmartBear Software, Inc.