Complex Numbers
OpenAPI does not provide support natively for complex numbers. The highest precision integer type is an integer
with an int64
format, while the highest precision decimal value in the spec is a type number
with a double
format.
In order to support arbitrary precision numbers, Speakeasy adds two new potential formats that you can use in your spec: bigint
and decimal
. These formats represent arbitrary precision integers, and arbitrary precision decimal numbers, respectively. When these formats are used, the generated SDK will use the language appropriate types to allow natively interacting with them.
Preserve Precision When Serializing
When using bigint
and decimal
formats, the generated SDK will always treat those values as arbitrary precision, and within the SDK, the precision will always be maintained.
During serialization, however, the value will be cast into the type
of the field, which may result in loss of precision. To avoid this, avoid using a numeric type
in your OpenAPI spec, and instead use the type string
and a format of bigint
or decimal
. This will ensure that the value is serialized with it’s full precision intact as a string (with the normal caveats of arbitrary precision decimal values in your language of choice).