Skip to content

Commit 95910fc

Browse files
authored
Merge pull request #3864 from handrews/request-examples-304
Improve media type serialization examples (3.0.4)
2 parents 44eda57 + e386f10 commit 95910fc

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

versions/3.0.4.md

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ This object MAY be extended with [Specification Extensions](#specificationExtens
13021302

13031303
##### Request Body Examples
13041304

1305-
A request body with a referenced model definition.
1305+
A request body with a referenced schema definition.
13061306
```json
13071307
{
13081308
"description": "user to add to the system",
@@ -1378,35 +1378,6 @@ content:
13781378
externalValue: http://foo.bar/examples/user-example.whatever
13791379
```
13801380

1381-
A body parameter that is an array of string values:
1382-
```json
1383-
{
1384-
"description": "user to add to the system",
1385-
"content": {
1386-
"text/plain": {
1387-
"schema": {
1388-
"type": "array",
1389-
"items": {
1390-
"type": "string"
1391-
}
1392-
}
1393-
}
1394-
}
1395-
}
1396-
```
1397-
1398-
```yaml
1399-
description: user to add to the system
1400-
required: true
1401-
content:
1402-
text/plain:
1403-
schema:
1404-
type: array
1405-
items:
1406-
type: string
1407-
```
1408-
1409-
14101381
#### <a name="mediaTypeObject"></a>Media Type Object
14111382
Each Media Type Object provides schema and examples for the media type identified by its key.
14121383

@@ -1566,9 +1537,35 @@ requestBody:
15661537
properties: {}
15671538
```
15681539

1569-
In this example, the contents in the `requestBody` MUST be stringified per [RFC1866](https://tools.ietf.org/html/rfc1866) when passed to the server. In addition, the `address` field complex object will be stringified.
1540+
In this example, the contents in the `requestBody` MUST be encoded per [RFC1866](https://tools.ietf.org/html/rfc1866) when passed to the server. In addition, the `address` field complex object will be serialized to a string representation prior to encoding.
1541+
1542+
When passing complex objects in the `application/x-www-form-urlencoded` content type, the default serialization strategy of such properties is described in the [Encoding Object](#encodingObject)'s [`style`](#encodingStyle) property as `form`.
1543+
1544+
With this example, given an `id` of `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` and a US-style address (with ZIP+4) as follows:
1545+
1546+
```json
1547+
{
1548+
"streetAddress": "123 Example Dr.",
1549+
"city": "Somewhere",
1550+
"state": "CA",
1551+
"zip": "99999+1234"
1552+
}
1553+
```
1554+
1555+
Assuming the most compact representation of the JSON value (with unnecessary whitespace removed), we would expect to see the following request body, where space characters have been replaced with `+` and `+`, `"`, `{`, and `}` have been percent-encoded to `%2B`, `%22`, `%7B`, and `%7D`, respectively:
15701556

1571-
When passing complex objects in the `application/x-www-form-urlencoded` content type, the default serialization strategy of such properties is described in the [`Encoding Object`](#encodingObject)'s [`style`](#encodingStyle) property as `form`.
1557+
```urlencoded
1558+
id=f81d4fae-7dec-11d0-a765-00a0c91e6bf6&address=%7B%22streetAddress%22:%22123+Example+Dr.%22,%22city%22:%22Somewhere%22,%22state%22:%22CA%22,%22zip%22:%2299999%2B1234%22%7D
1559+
```
1560+
1561+
Note that the `id` keyword is treated as `text/plain` per the [Encoding Object](#encodingObject)'s default behavior, and is serialized as-is.
1562+
If it were treated as `application/json`, then the serialized value would be a JSON string including quotation marks, which would be percent-encoded as `%22`.
1563+
1564+
Here is the `id` parameter (without `address`) serialized as `application/json` instead of `text/plain`, and then encoded per RFC1866:
1565+
1566+
```urlencoded
1567+
id=%22f81d4fae-7dec-11d0-a765-00a0c91e6bf6%22
1568+
```
15721569

15731570
##### Special Considerations for `multipart` Content
15741571

0 commit comments

Comments
 (0)