Skip to content

Commit f0ebca0

Browse files
authored
Merge pull request #4045 from handrews/format
Clarify data model types and formats
2 parents 4573bd7 + 8f626a5 commit f0ebca0

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

versions/3.1.1.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,35 @@ Note that no aspect of implicit connection resolution changes how [URIs are reso
199199

200200
### Data Types
201201

202-
Data types in the OAS are based on the types supported by the [JSON Schema Specification Draft 2020-12](https://tools.ietf.org/html/draft-bhutton-json-schema-00#section-4.2.1).
203-
Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part.
204-
Models are defined using the [Schema Object](#schema-object), which is a superset of JSON Schema Specification Draft 2020-12.
202+
Data types in the OAS are based on the types defined by the [JSON Schema Validation Specification Draft 2020-12](https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.1.1):
203+
"null", "boolean", "object", "array", "number", "string", or "integer".
204+
Models are defined using the [Schema Object](#schema-object), which is a superset of the JSON Schema Specification Draft 2020-12.
205205

206-
<a name="data-type-format"></a>As defined by the [JSON Schema Validation specification](https://tools.ietf.org/html/draft-bhutton-json-schema-validation-00#section-7.3), data types can have an optional modifier keyword: `format`. As described in that specification, `format` is treated as a non-validating annotation by default; the ability to validate `format` varies across implementations.
206+
207+
JSON Schema keywords and `format` values operate on JSON "instances" which may be one of the six JSON data types, "null", "boolean", "object", "array", "number", or "string", with certain keywords and formats only applying to a specific type. For example, the `pattern` keyword and the `date-time` format only apply to strings, and treat any instance of the other five types as _automatically valid._ This means JSON Schema keywords and formats do **NOT** implicitly require the expected type. Use the `type` keyword to explicitly constrain the type.
208+
209+
Note that the `type` keyword allows `"integer"` as a value for convenience, but keyword and format applicability does not recognize integers as being of a distinct JSON type from other numbers because [[RFC7159|JSON]] itself does not make that distinction. Since there is no distinct JSON integer type, JSON Schema defines integers mathematically. This means that both `1` and `1.0` are [equivalent](https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-4.2.2), and are both considered to be integers.
210+
211+
#### Data Type Format
212+
213+
As defined by the [JSON Schema Validation specification](https://tools.ietf.org/html/draft-bhutton-json-schema-validation-00#section-7.3), data types can have an optional modifier keyword: `format`. As described in that specification, `format` is treated as a non-validating annotation by default; the ability to validate `format` varies across implementations.
207214

208215
The OpenAPI Initiative also hosts a [Format Registry](https://spec.openapis.org/registry/format/) for formats defined by OAS users and other specifications. Support for any registered format is strictly OPTIONAL, and support for one registered format does not imply support for any others.
209216

210217
Types that are not accompanied by a `format` keyword follow the type definition in the JSON Schema. Tools that do not recognize a specific `format` MAY default back to the `type` alone, as if the `format` is not specified.
218+
For the purpose of [JSON Schema validation](https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-7.1), each format should specify the set of JSON data types for which it applies. In this registry, these types are shown in the "JSON Data Type" column.
211219

212220
The formats defined by the OAS are:
213221

214-
| [`type`](#data-types) | [`format`](#data-type-format) | Comments |
215-
| -------------------- | --------------------------- | ---------------------------- |
216-
| `integer` | `int32` | signed 32 bits |
217-
| `integer` | `int64` | signed 64 bits (a.k.a long) |
218-
| `number` | `float` | |
219-
| `number` | `double` | |
220-
| `string` | `password` | A hint to obscure the value. |
222+
| `format` | JSON Data Type | Comments |
223+
| ---------- | -------------- | ---------------------------- |
224+
| `int32` | number | signed 32 bits |
225+
| `int64` | number | signed 64 bits (a.k.a long) |
226+
| `float` | number | |
227+
| `double` | number | |
228+
| `password` | string | A hint to obscure the value. |
229+
230+
As noted under [Data Type](#data-types), both `type: number` and `type: integer` are considered to be numbers in the data model.
221231

222232
#### Working With Binary Data
223233

0 commit comments

Comments
 (0)