Skip to content

Commit 4c988a2

Browse files
committed
Re-organize form-urlencoded guidance (3.1.1 port of 3923 4/6)
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 1371a93 commit 4c988a2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

versions/3.1.1.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,13 +1718,15 @@ The absence of all three of those fields is the equivalent of using `content`, b
17181718

17191719
##### Encoding the `x-www-form-urlencoded` Media Type
17201720

1721-
See [Appendix E](#percentEncodingAndFormMediaTypes) for a detailed examination of percent-encoding concerns for form media types.
1721+
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).
1722+
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.
17221723

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

17261726
###### Example: URL Encoded Form with JSON Values
17271727

1728+
When there is no [`encoding` field](#mediaTypeEncoding), the serialization strategy is based on the Encoding Object's default values:
1729+
17281730
```yaml
17291731
requestBody:
17301732
content:
@@ -1741,11 +1743,7 @@ requestBody:
17411743
properties: {}
17421744
```
17431745

1744-
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.
1745-
1746-
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`.
1747-
1748-
With this example, given an `id` of `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` and a US-style address (with ZIP+4) as follows:
1746+
With this example, consider an `id` of `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` and a US-style address (with ZIP+4) as follows:
17491747

17501748
```json
17511749
{
@@ -1773,7 +1771,7 @@ id=%22f81d4fae-7dec-11d0-a765-00a0c91e6bf6%22
17731771

17741772
###### Example: URL Encoded Form with Binary Values
17751773

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

17781776
```YAML
17791777
requestBody:
@@ -1785,15 +1783,22 @@ requestBody:
17851783
name:
17861784
type: string
17871785
icon:
1788-
# default for type string is text/plain, need to declare
1789-
# the appropriate contentType in the Encoding Object
1786+
# The default with "contentEncoding" is application/octet-stream,
1787+
# so we need to set image media type(s) in the Encoding Object.
17901788
type: string
17911789
contentEncoding: base64url
17921790
encoding:
17931791
icon:
17941792
contentType: image/png, image/jpeg
17951793
```
17961794

1795+
Given a name of `example` and a solid red 2x2-pixel PNG for `icon`, this
1796+
would produce a request body of:
1797+
1798+
```urlencoded
1799+
name=example&icon=iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAAEklEQVQIW2P8z8AARAwMjDAGACwBA/+8RVWvAAAAAElFTk
1800+
```
1801+
17971802
##### Encoding `multipart` Media Types
17981803

17991804
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)