Vocabulary Data Types

Vocabulary data types are used to define a list of possible values for a particular data type, that is, to create a vocabulary for data.

The vocabulary data type is created as follows:

  1. The first row is the header.

    It starts with the Datatype keyword, followed by the vocabulary data type name. The predefined data type is in angle brackets based on which the vocabulary data type is created at the end.

  2. The second and following rows list values of the vocabulary data type.

    The values can be of the indicated predefined data type only.

Supported Base Types

The base type specified in the angle brackets can be any non-array scalar type available in the OpenL binding context, including:

  • Text types, such as String and Character
  • Numeric types, both primitive and boxed, such as int/Integer, double/Double, long/Long, short/Short, byte/Byte, float/Float, BigDecimal, and BigInteger
  • Boolean / boolean
  • Date
  • Range types, such as IntRange, DoubleRange, DateRange
  • User-defined vocabulary or datatype names from the same or imported module

Arrays and collections are not allowed as the base type. For example, Datatype MyType <String[]>, Datatype MyType <List> and Datatype MyType <Map> are rejected with an error.

Example

In the example described in Introducing Datatype Tables, the data type Person has an attribute gender of the Gender data type which is the following vocabulary data type.

Datatype Gender <String>
Male
Female

Example of vocabulary datatype table with String parameters

Thus, data of Gender data type can only be Male or Female.

OpenL Tablets checks all data of the vocabulary data type on whether its value is in the defined list of possible values. If the value is outside of the valid domain, or defined vocabulary, OpenL Tablets displays an appropriate error. Usage of vocabulary data types provides data integrity and allows users to avoid accidental mistakes in rules.

A decision table condition compares a column of a vocabulary data type with a value of its base type, such as a String argument, in the base type. A value that is not in the vocabulary equals no value of the column, so only a range that holds it or a rule whose condition cell is empty matches it, and it is not reported as an error. A table that has to reject such a value can end with a rule that leaves the condition cell empty and returns the result of the ERROR function.

Vocabulary Values in OpenAPI

OpenL Rule Services publishes the values of a vocabulary data type as the enum of the OpenAPI schema wherever the type is used:

  • a field of a datatype, and the elements of an array field
  • a parameter of a rule, alone or among others, and the elements of an array parameter
  • a cell of a spreadsheet result
  • the returned value of a rule

A client therefore sees which values a service accepts and returns. An array of arrays of a vocabulary is published without the values.

OpenL Studio treats the enum of an OpenAPI file the same way: the reconciliation of a project against its OpenAPI file requires a vocabulary data type with the same values wherever the file lists them, and the generation of a project from an OpenAPI file creates a vocabulary data type for every enum. For details, see OpenL Studio Guide > Reconciling an OpenAPI Project and OpenL Studio Guide > Vocabulary Data Types.