Data types in RAML

When declaring request parameters, path parameters, request body, response body, … in RAML, we need to declare the data type of these information. RAML defines many different data types that help us to meet our needs. In this tutorial, we will learn about data types in RAML!

First, look at the image below, in general, RAML defines the hierarchical data types as follows:

As you can see, at the top of the diagram above, we have a data type of any. Information defined with type any will have no restrictions at all, you can define numbers, letters, objects, whatever data types you want.

Underneath any data type, we have more detailed, specific data types that are more restrictive if the information is defined by these data types. As you can see, we have scalar types, array, object, union, XSD schema and even JSON schema.

Scalar types

In short, scalar types are simple data types that are not defined from other data types, such as boolean, string, null, file,… Values ​​of information are defined with scalars types are single, boolean has only true, false; string then the values ​​are just strings…


We only declare the date and year for this data type and follow the format defined by the Internet standard for time RFC 3339.



In contrast to date-only, this data type only allows us to define hours, minutes, seconds, it does not support days, months, and years with timezone and it also follows RFC 3339 format!



There are 2 supported formats for datetime data type, RFC 3339 and RFC 2616. By default, if we don’t tell the format, the format used will be RFC 3339.



Many of you may wonder if there is a datetime data type, what does the datetime-only data type mean? Actually, datetime-only is a combination of date-only and time-only guys, they are separated by the letter “T” and this data type does not support timezone!



Number is a data type common to all data types related to numbers. It allows us to define the minimum value, the maximum value, what the format is: int, int8, int16, int32, int64, long, float, double.



This is a data type that inherits the number data type with an integer value.



The value of the data type is just true or false, representing correctness.



We can define String according to the pattern with minLength and maxLength, for example like this:


This is the data type that allows the field to be undefined.

For example, if you define a Student object with a field name that cannot be null as follows:

then you cannot define example as follows:

We can define the Student object as follows:

then we can define example as follows:


This data type is for the management of file-related information. We can specify the file format, minLength and maxLength size in bytes for this data type.



The array data type helps us define an array of data, which can be a string array, a number array or even an array of objects, just like in Java!

You need to specify which data type the item in the array is, whether it needs to be unique or not, and you can also specify the limit on the number of items in the array by minItems and maxItems.



Object helps us define information about the object, with many properties belonging to this object. In the above examples, I have defined the object data type for Student.



Union is a data type that allows us to define values using many different data types.

For example, the properties name in the following Student object can be null or string.

XSD and JSON schema

XSD and JSON schema help us define data types using XML and JSON schema.

Add Comment