Skip to content

Commit 8cdbf83

Browse files
committed
Re-organize form-urlencoded guidance
This re-organizes and streamlines the form-urlencoded guidance that was consolidated from the Media Type Object. It also adds an example of a base64-encoded URL query parameter.
1 parent fd71328 commit 8cdbf83

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

versions/3.0.4.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,13 +1648,15 @@ This makes the presence of at least one of `style`, `explode`, or `allowReserved
16481648

16491649
##### Encoding the `x-www-form-urlencoded` Media Type
16501650

1651-
See [Appendix E](#percentEncodingAndFormMediaTypes) for a detailed examination of percent-encoding concerns for form media types.
1651+
To submit content using form url encoding via [RFC1866](https://tools.ietf.org/html/rfc1866), use the `application/x-www-form-urlencoded` media type in the [Media Type Object](#mediaTypeObject) under the [Request Body Object](#requestBodyObject).
1652+
This configuration means that the request body MUST be encoded per [RFC1866](https://tools.ietf.org/html/rfc1866) when passed to the server, after any complex objects have been serialized to a string representation.
16521653

1653-
To submit content using form url encoding via [RFC1866](https://tools.ietf.org/html/rfc1866), the following
1654-
definition may be used:
1654+
See [Appendix E](#percentEncodingAndFormMediaTypes) for a detailed examination of percent-encoding concerns for form media types.
16551655

16561656
###### Example: URL Encoded Form with JSON Values
16571657

1658+
When there is no [`encoding` field](#mediaTypeEncoding), the serialization strategy is based on the Encoding Object's default values:
1659+
16581660
```yaml
16591661
requestBody:
16601662
content:
@@ -1671,11 +1673,7 @@ requestBody:
16711673
properties: {}
16721674
```
16731675

1674-
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.
1675-
1676-
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`.
1677-
1678-
With this example, given an `id` of `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` and a US-style address (with ZIP+4) as follows:
1676+
With this example, consider an `id` of `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` and a US-style address (with ZIP+4) as follows:
16791677

16801678
```json
16811679
{
@@ -1703,7 +1701,7 @@ id=%22f81d4fae-7dec-11d0-a765-00a0c91e6bf6%22
17031701

17041702
###### Example: URL Encoded Form with Binary Values
17051703

1706-
`application/x-www-form-urlencoded` is a text format, which requires base64-encoding any binary data:
1704+
Note that `application/x-www-form-urlencoded` is a text format, which requires base64-encoding any binary data:
17071705

17081706
```YAML
17091707
requestBody:
@@ -1715,14 +1713,22 @@ requestBody:
17151713
name:
17161714
type: string
17171715
icon:
1718-
# default is text/plain, need to declare an image type only!
1716+
# The default with "format: byte" is application/octet-stream,
1717+
# so we need to set image media type(s) in the Encoding Object.
17191718
type: string
17201719
format: byte
17211720
encoding:
17221721
icon:
17231722
contentType: image/png, image/jpeg
17241723
```
17251724

1725+
Given a name of `example` and a solid red 2x2-pixel PNG for `icon`, this
1726+
would produce a request body of:
1727+
1728+
```urlencoded
1729+
name=example&icon=iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAEklEQVQIW2P8z8AARAwMjDAGACwBA/+8RVWvAAAAAElFTk
1730+
```
1731+
17261732
##### Encoding `multipart` Media Types
17271733

17281734
It is common to use `multipart/form-data` as a `Content-Type` when transferring request bodies to operations. In contrast to 2.0, a `schema` is REQUIRED to define the input parameters to the operation when using `multipart` content. This supports complex structures as well as supporting mechanisms for multiple file uploads.

0 commit comments

Comments
 (0)