numbers and integers
The number/integer types allows the describing of various number formats through a combination of the type and format attribute, along with a number of attributes for validating the data, the spec should cover most use cases.
Available formats are:
Type | Format | Explanation | Example |
---|---|---|---|
number | Any number integer/float at any precision. | 10 or 1.9 or 9223372036854775807 | |
number | float | 32-bit floating point number. | 1.9 |
number | double | 64-bit floating point number. | 1.7976931348623157 |
integer | Any integer number. | 2147483647 or 9223372036854775807 | |
integer | int32 | 32-bit integer. | 2147483647 |
integer | int64 | 64-bit integer. | 9223372036854775807 |
Below are some examples of defining number/integer types:
# Any numberschema:type: number# A 32-bit floating point numberschema:type: numberformat: float# A 64-bit floating point numberschema:type: numberformat: double# Any integerschema:type: integer# A 32-bit integerschema:type: integerformat: int32# A 64-bit integerschema:type: integerformat: int64
Various tools may treat a number/integer without a format attribute as a type capable of holding the closest representation of that number in the target language. For example, a number might be represented by a double, and an integer by an int64. Therefore, it’s recommended that you be explicit with the format of your number type and always populate the format attribute.
The number type also has some optional attributes for additional validation:
- minimum - The minimum inclusive number the value should contain.
- maximum - The maximum inclusive number the value should contain.
- exclusiveMinimum - Make the minimum number exclusive.
- exclusiveMaximum - Make the maximum number exclusive.
- multipleOf - Specify the number/integer is a multiple of the provided value.
Some examples are below:
# An integer with a minimum inclusive value of 0schema:type: integerformat: int32minimum: 10# An integer with a minimum exclusive value of 0schema:type: integerformat: int32minimum: 0exclusiveMinimum: true# A float with a range between 0 and 1schema:type: numberformat: floatminimum: 0maximum: 1# A double with an exclusive maximum of 100schema:type: numberformat: doublemaximum: 100exclusiveMaximum: true# An 64 but integer that must be a multiple of 5schema:type: integerformat: int64multipleOf: 5