The cost of using double instead of float is notional in 99% of cases however the cost of a subtle bug due to rounding error is much higher. int x = 1111111111 įloat has very little precision (6-7 digits) and shows significant rounding error fairly easily. In 99% of cases, double is a better choice. The value of items is a schema that describes the type and format of array items.You shouldn't use float unless you have to. Unlike JSON Schema, the items keyword is required in arrays. In objects, a nullable property is not the same as an optional property, but some tools may choose to map an optional property to the null value. The example above may be mapped to the nullable types int? in C# and in Java. Note that null is different from an empty string "". OpenAPI 3.0 does not have an explicit null type as in JSON Schema, but you can use nullable: true to specify that the value may be null. Note that truthy and falsy values such as "true", "", 0 or null are not considered boolean values. The ^…$ token forces an exact match.īoolean type: boolean represents two values: true and false. For example, pattern: pet matches pet, petstore and carpet. Without ^…$, pattern works as a partial match, that is, matches any string that contains the specified regular expression. Note that the regular expression is enclosed in the ^…$ tokens, where ^ means the beginning of the string, and $ means the end of the string. For example, the following pattern matches a Social Security Number (SSN) in the 123-45-6789 format: Regular expressions are case-sensitive, that is, and are different expressions. The regular expression syntax used is from JavaScript (more specifically, ECMA 262). Only the values that match this template will be accepted. The pattern keyword lets you define a regular expression template for the string value. Tools that do not support a specific format may default back to the type alone, as if the format is not specified. Tools can use the format to validate the input or to map the value to a specific type in the chosen programming language.
However, format is an open value, so you can use any formats, even not those defined by the OpenAPI Specification, such as: binary – binary data, used to describe files (see Files below).
password – a hint to UIs to mask the input.date-time – the date-time notation as defined by RFC 3339, section 5.6, for example,.date – full-date notation as defined by RFC 3339, section 5.6, for example,.OpenAPI defines the following built-in string formats: Note that an empty string "" is a valid string unless minLength or pattern is specified.Īn optional format modifier serves as a hint at the contents and format of the string. String length can be restricted using minLength and maxLength: The value of multipleOf must be a positive number, that is, you cannot use multipleOf: -5. multipleOf may be used with floating-point numbers, but in practice this can be unreliable due to the limited precision or floating point math. Use the multipleOf keyword to specify that a number must be the multiple of another number: The word “exclusive” in exclusiveMinimum and exclusiveMaximum means the corresponding boundary is excluded: For example, you can define a floating-point number range as 0–50 and exclude the 0 value: To exclude the boundary values, specify exclusiveMinimum: true and exclusiveMaximum: true. Use the minimum and maximum keywords to specify the range of possible values:īy default, the minimum and maximum values are included in the range, that is: Note that strings containing numbers, such as "17", are considered strings and not numbers. Signed 32-bit integers (commonly used integer type). An optional format keyword serves as a hint for the tools to use a specific numeric type:įloating-point numbers with double precision. OpenAPI has two numeric types, number and integer, where number includes both integer and floating-point numbers. Mixed types can be described using oneOf and anyOf, which specify a list of alternate types: type as a list is not valid in OpenAPI (even though it is valid in JSON Schema): Note that there is no null type instead, the nullable attribute is used as a modifier of the base type.Īdditional type-specific keywords can be used to refine the data type, for example, limit the string length or specify an enum of possible values. Using these types, you can describe any data structures. These types exist in most programming languages, though they may go by different names. OpenAPI defines the following basic types: The data type of a schema is defined by the type keyword, for example, type: string.