Skip to content

Commit ee93ed9

Browse files
Merge pull request #5422 from karenetheridge/ether/v3.3-encoding-deserialization
v3.3: clarify how encoding works for deserialization too
2 parents 15fb9e6 + 7395fd6 commit ee93ed9

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/oas.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,11 +1376,13 @@ Each field has its own set of media types with which it can be used; for all oth
13761376
The behavior of the `encoding` field is designed to support web forms, and is therefore only defined for media types structured as name-value pairs that allow repeat values, most notably `application/x-www-form-urlencoded` and `multipart/form-data`.
13771377

13781378
To use the `encoding` field, each key under the field MUST exist in the data instance as a property; `encoding` entries with no corresponding property SHALL be ignored.
1379-
Array properties MUST be handled by applying the given Encoding Object to produce one encoded value per array item, each with the same `name`, as is recommended by [[!RFC7578]] [Section 4.3](https://www.rfc-editor.org/rfc/rfc7578.html#section-4.3) for supplying multiple values per form field.
1380-
For all other value types for both top-level non-array properties and for values, including array values, within a top-level array, the Encoding Object MUST be applied to the entire value.
1379+
When serializing, property values of the array type MUST be handled by applying the given Encoding Object to produce one encoded value per array item, each with the same `name`, as is recommended by [[!RFC7578]] [Section 4.3](https://www.rfc-editor.org/rfc/rfc7578.html#section-4.3) for supplying multiple values per form field; when deserializing, the Encoding object is applied to each item of the array property of the same name.
1380+
For deserialization to an object, multiple values with the same `name` MUST be collapsed into an array value for that named property, with one item per value, in order.
1381+
For all other value types for both top-level non-array property values and for other values, including items of the array type within a top-level array, the Encoding Object MUST be applied to the entire value.
1382+
13811383
The order of these name-value pairs in the target media type is implementation-defined when not explicitly defined by that media-type's specification.
13821384

1383-
For `application/x-www-form-urlencoded`, the `encoding` keys MUST map to parameter names, with the values produced according to the rules of the [Encoding Object](#encoding-object).
1385+
For `application/x-www-form-urlencoded`, the `encoding` keys MUST map to parameter names, with the serialized values produced according to the rules of the [Encoding Object](#encoding-object).
13841386
See [Encoding the `x-www-form-urlencoded` Media Type](#encoding-the-x-www-form-urlencoded-media-type) for guidance and examples, both with and without the `encoding` field.
13851387

13861388
For `multipart` types that decode to an object, such as `multipart/form-data`, the `encoding` keys MUST map to the [`name` parameter](https://www.rfc-editor.org/rfc/rfc7578#section-4.2) of the `Content-Disposition: form-data` header of each part, as is defined for `multipart/form-data` in [[!RFC7578]].
@@ -1927,11 +1929,19 @@ requestBody:
19271929
schema:
19281930
type: object
19291931
properties:
1930-
# No Encoding Object, so use default `text/plain`
1932+
# No Encoding Object for this property, so use string default `text/plain`
19311933
id:
19321934
type: string
19331935
format: uuid
19341936

1937+
# An Encoding object allows multiple values to be provided for this
1938+
# property, without any attempt to decode the array as application/json
1939+
alias:
1940+
type: [ string, array ]
1941+
pattern: '^[A-Z][a-z]*$'
1942+
items:
1943+
pattern: '^[A-Z][a-z]*$'
1944+
19351945
# Encoding Object overrides the default `application/json` content type
19361946
# for each item in the array with `application/xml; charset=utf-8`
19371947
addresses:
@@ -1945,6 +1955,8 @@ requestBody:
19451955
profileImage: {}
19461956

19471957
encoding:
1958+
alias:
1959+
contentType: text/plain
19481960
addresses:
19491961
contentType: application/xml; charset=utf-8
19501962
profileImage:

0 commit comments

Comments
 (0)