Data type conversion
In high-level RESTful Web services the GWS can refine data types using JSON schema restriction keywords in the schema for types.
The OpenAPI specification defines data types for basic types, such as string, date, and number. These generally correspond to Genero BDL primitive data types.
When you need to restrict a data type (for example, to match data constraints defined on a
database), the GWS can refine data types by applying JSON attribute keywords to the type
specification in the schema it generates. The following sections describe how the GWS refines data
types for VARCHAR
, DATE
/DATETIME
, and
DECIMAL(P,S)
.
VARCHAR(N)
string
. For a
string
type to define a VARCHAR(N)
of length N, the GWS can
restrict its size by using the maxLength
keyword.
schema
type "string"
maxLength 10
fglrestful generates the data type in the client stub, mapping it to a Genero
BDL VARCHAR(10)
type.
DATE/DATETIME
OpenAPI defines a date type as a string
. The format
keyword can
give this as a full date
(2021-07-15), or as a date-time
(2021-07-15T16:39:28Z).
As a DATE
schema
type "string"
format "date"
fglrestful generates the data type in the client stub, mapping it to a Genero
BDL DATE
type.
As a DATETIME
schema
type "string"
format "date-time"
fglrestful generates the data type in the client stub, mapping it to a Genero
BDL DATETIME YEAR TO SECOND
type.
By default fglrestful generates DATETIME YEAR TO SECOND
. You
can configure how the GWS refines the fraction part of a DATETIME
type at the command level. For example, to generate
DATETIME YEAR TO FRACTION(3)
, you can set the option --datetime-fraction=3
in the fglrestful tool command.
DECIMAL(p,s)
number
. For a number
type to represent a fixed point decimal with
precision and scale (a Genero BDL DECIMAL(p,s)
), the GWS defines it with several
JSON schema restriction keywords:schema
type "number"
multipleOf 0.01
minimum -1000
exclusiveMinimum true
maximum 1000
exclusiveMaximum true
- The precision (p) is calculated from the
maximum
andminimum
values. Themaximum
is calculated by subtracting themultipleOf
value from themaximum
:Maximum = 1000 - 0.01 = 999.99
multipleOf
to the minimum:
If the keywordsMinimum = -1000 + 0.01 = -999.99
exclusiveMinimum
andexclusiveMaximum
are set to true, the corresponding boundary is excluded. In the example, the minimum value (-1000) and the maximum (1000) are excluded. -
To calculate the scale (s), fglrestful does a conversion based on the value of the
multipleOf
attribute.multipleOf
can have two values:multipleOf
= 0.01 is converted toDECIMAL(p,2)
, meaning the number of size p has two decimal places.multipleOf
= 1 is converted toDECIMAL(p,0)
, meaning the number of size p has no decimal place.- If there is no
multipleOf
, the number is converted toDECIMAL(p)
, meaning it can be any number of size p with or without decimals. There is no fixed decimal place.
In this example, fglrestful generates the data type in the client stub,
mapping it to a Genero BDL DECIMAL(5,2)
type. The fraction is written as
DECIMAL(5,2)
because five digits are needed for the precision and the scale, for
example 999.99.