You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versions/3.0.4.md
+28
Original file line number
Diff line number
Diff line change
@@ -1049,6 +1049,7 @@ There are four possible parameter locations specified by the `in` field:
1049
1049
1050
1050
The rules for serialization of the parameter are specified in one of two ways.
1051
1051
Parameter Objects MUST include either a `content` field or a `schema` field, but not both.
1052
+
See [Appendix B](#dataTypeConversion) for a discussion of converting values of various types to string representations.
1052
1053
1053
1054
###### Common Fixed Fields
1054
1055
@@ -1618,6 +1619,7 @@ An `encoding` attribute is introduced to give you control over the serialization
1618
1619
#### <a name="encodingObject"></a>Encoding Object
1619
1620
1620
1621
A single encoding definition applied to a single schema property.
1622
+
See [Appendix B](#dataTypeConversion) for a discussion of converting values of various types to string representations.
1621
1623
1622
1624
##### Fixed Fields
1623
1625
Field Name | Type | Description
@@ -3700,6 +3702,32 @@ Version | Date | Notes
3700
3702
3701
3703
## <a name="dataTypeConversion"></a>Appendix B: Data Type Conversion
3702
3704
3705
+
Serializing typed data to plain text, which can occur in `text/plain` message bodies or `multipart` parts, as well as in the `application/x-www-form-urlencoded` format in either URL query strings or message bodies, involves significant implementation- or application-defined behavior.
3706
+
3707
+
Schema Objects validate data based on the [JSON Schema data model](https://datatracker.ietf.org/doc/html/draft-wright-json-schema-00#section-4.2), which only recognizes four primitive data types: strings (which are [only broadly interoperable as UTF-8](https://datatracker.ietf.org/doc/html/rfc7159#section-8.1)), numbers, booleans, and `null`.
3708
+
Notably, integers are not a distinct type from other numbers, with `type: integer` being a convenience defined mathematically, rather than based on the presence or absence of a decimal point in any string representation.
3709
+
3710
+
The [Parameter Object](#parameterObject) and [Encoding Object](#encodingObject) offer features to control how to arrange values from array or object types.
3711
+
They can also be used to control how strings are further encoded to avoid reserved or illegal characters.
3712
+
However, there is no general-purpose specification for converting schema-validated non-UTF-8 primitive data types (or entire arrays or objects) to strings.
3713
+
3714
+
Two cases do offer standards-based guidance:
3715
+
3716
+
* [RFC3987 §3.1](https://datatracker.ietf.org/doc/html/rfc3987#section-3.1) provides guidance for converting non-Unicode strings to UTF-8, particularly in the context of URIs (and by extension, the form media types which use the same encoding rules)
3717
+
* [RFC6570 §2.3](https://www.rfc-editor.org/rfc/rfc6570#section-2.3) specifies which values, including but not limited to `null`, are considered _undefined_ and therefore treated specially in the expansion process when serializing based on that specification
3718
+
3719
+
Implementations of RFC6570 often have their own conventions for converting non-string values, but these are implementation-specific and not defined by the RFC itself.
3720
+
This is one reason for the OpenAPI Specification to leave these conversions as implementation-defined: It allows using RFC6570 implementations regardless of how they choose to perform the conversions.
3721
+
3722
+
To control the serialization of numbers, booleans, and `null` (or other values RFC6570 deems to be undefined) more precisely, schemas can be defined as `type: string` and constrained using `pattern`, `enum`, `format`, and other keywords to communicate how applications must pre-convert their data prior to schema validation.
3723
+
The resulting strings would not require any further type conversion.
3724
+
3725
+
The `format` keyword can assist in serialization.
3726
+
Some formats (such as `date-time` or `byte`) are unambiguous, while others (such as [`decimal`](https://spec.openapis.org/registry/format/decimal.html) in the [Format Registry](https://spec.openapis.org/registry/format/)) are less clear.
3727
+
However, care must be taken with `format` to ensure that the specific formats are supported by all relevant tools as unrecognized formats are ignored.
3728
+
3729
+
Requiring input as pre-formatted, schema-validated strings also improves round-trip interoperability as not all programming languages and environments support the same data types.
3730
+
3703
3731
## <a name="usingRFC6570Implementations"></a>Appendix C: Using RFC6570 Implementations
3704
3732
3705
3733
Serialization is defined in terms of RFC6570 URI Templates in two scenarios:
0 commit comments