Skip to content

Commit 73644ca

Browse files
committed
documented requestBody
1 parent ce3a579 commit 73644ca

File tree

1 file changed

+180
-1
lines changed

1 file changed

+180
-1
lines changed

versions/3.0.md

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ Field Name | Type | Description
580580
<a name="operationExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this operation.
581581
<a name="operationId"></a>operationId | `string` | Unique string used to identify the operation. The id MUST be unique among all operations described in the API. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is recommended to follow common programming naming conventions.
582582
<a name="operationParameters"></a>parameters | [[Parameter Object](#parameterObject) <span>&#124;</span> [Reference Object](#referenceObject)] | A list of parameters that are applicable for this operation. If a parameter is already defined at the [Path Item](#pathItemParameters), the new definition will override it, but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a [name](#parameterName) and [___location](#parameterIn). The list can use the [Reference Object](#referenceObject) to link to parameters that are defined at the [OpenAPI Object's parameters](#oasParameters).
583-
<a name="operationRequestBody"></a>requestBody | [[Request Body Object](#requestBodyObject) <span>&#124;</span> [Reference Object](#referenceObject)] | The request body applicable for this operation.
583+
<a name="operationRequestBody"></a>requestBody | [[Request Body Object](#requestBodyObject) <span>&#124;</span> [Reference Object](#referenceObject)] | The request body applicable for this operation. The `requestBody` is only supported in HTTP methods where the [HTTP 1.1 specification](https://tools.ietf.org/html/rfc7231#section-4.3.1) has explicitly defined semantics for request bodies.
584584
<a name="operationResponses"></a>responses | [Responses Object](#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation.
585585
<a name="operationCallbacks"></a>callback responses | [Callback Responses Object](#callbackObject) | The list of possible callback responses as they are returned from executing this operation.
586586
<a name="operationDeprecated"></a>deprecated | `boolean` | Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`.
@@ -1124,6 +1124,185 @@ application/json:
11241124
11251125
```
11261126

1127+
##### Considerations for file uploads
1128+
1129+
In contrast with the 2.0 specification, describing `file` input/output content in OpenAPI is
1130+
described with the same semantics as any other schema type. Specifically:
1131+
1132+
```yaml
1133+
# content transferred with base64 encoding
1134+
schema:
1135+
type: string
1136+
format: base64
1137+
1138+
# content transfered in binary (octet-stream):
1139+
schema:
1140+
type: string
1141+
format: binary
1142+
1143+
# mutliple files:
1144+
schema:
1145+
type: array
1146+
items:
1147+
type: string
1148+
format: binary
1149+
```
1150+
1151+
Note that the above examples apply to either input payloads (i.e. file uploads) or response payloads.
1152+
1153+
1154+
A `requestBody` example for submitting a file in a `POST` operation therefore may look like the following:
1155+
1156+
```yaml
1157+
requestBody:
1158+
# any media type is accepted, functionally equivalent to `*/*`
1159+
application/octet-stream:
1160+
content:
1161+
schema:
1162+
# a binary file of any type
1163+
type: string
1164+
format: binary
1165+
```
1166+
1167+
In addition, specific media types may be specified:
1168+
1169+
```yaml
1170+
# multiple, specific media types may be specified:
1171+
requestBody:
1172+
# a binary file of type png or jpeg
1173+
content:
1174+
'image/png, image/jpeg':
1175+
schema:
1176+
type: string
1177+
format: binary
1178+
```
1179+
1180+
##### Support for x-www-form-urlencoded request bodies
1181+
1182+
To submit content using form url encoding via RFC 1866, the following
1183+
definition may be used:
1184+
1185+
```yaml
1186+
requestBody:
1187+
content:
1188+
x-www-form-urlencoded:
1189+
schema:
1190+
type: object
1191+
properties:
1192+
id:
1193+
type: string
1194+
format: uuid
1195+
address:
1196+
# complex types are stringified to support rfc1866
1197+
type: object
1198+
properties: {}
1199+
```
1200+
1201+
Note that in the above example, the contents in the `requestBody` must be stringified per RFC1866 when being passed to the server. In addition, the `address` field complex object will be strigified as well.
1202+
1203+
When passing complex objects in the `x-www-form-urlencoded` content type, the default serialization strategy of such properties is described in the `parameterContent` section as `deepObject`.
1204+
1205+
##### Special Considerations for `mutlipart` content
1206+
1207+
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 allows complex structures as well as supports mechanisms for multiple file uploads.
1208+
1209+
When passing in `multipart` types, boundaries may be used to separate sections of the content being transferred--thus, the following default `Content-Type`s are defined for `multipart/*`:
1210+
1211+
* If the property is a primitive, or an array of primitive values, the default Content-Type is `text/plain`
1212+
* If the property is complex, or an array of complex values, the default Content-Type is `application/json`
1213+
* If the property is a `type: string` with `format: binary` or `format: base64` (aka a file object), the default Content-Type is `application/octet-stream`
1214+
1215+
1216+
Examples:
1217+
1218+
```yaml
1219+
requestBody:
1220+
content:
1221+
multipart/form-data:
1222+
schema:
1223+
type: object
1224+
properties:
1225+
id:
1226+
type: string
1227+
format: uuid
1228+
address:
1229+
# default Content-Type for objects is `application/json`
1230+
type: object
1231+
properties: {}
1232+
profileImage:
1233+
# default Content-Type for string/binary is `application/octet-stream`
1234+
type: string
1235+
format: binary
1236+
children:
1237+
# default Content-Type for arrays is based on the `inner` type (text/plain here)
1238+
type: array
1239+
items:
1240+
type: string
1241+
addresses:
1242+
# default Content-Type for arrays is based on the `inner` type (object shown, so `application/json` in this example)
1243+
type: array
1244+
items:
1245+
type: '#/definitions/Address'
1246+
```
1247+
1248+
In scenarios where more control is needed over the Content-Type for `multipart` request bodies, an `encoding` attribute is introduced. This attribute is _only_ applicable to `mulitpart/*` request bodies.
1249+
1250+
#### <a name="encodingObject"></a>Encoding Object
1251+
1252+
An object representing multipart region encoding for `requestBody` objects
1253+
1254+
##### Patterned Fields
1255+
Field Pattern | Type | Description
1256+
---|:---:|---
1257+
<a name="encodingObjectProperty"></a>The property to apply encoding to | [Encoding Property](#encodingProperty) <span>&#124;</span> [Encoding](#encoding) | The field name to apply special encoding attributes to. This field must exist in the schema as a property. To avoid collisions with specification extensions, properties may not begin with `x-`.
1258+
1259+
This object can be extended with [Specification Extensions](#specificationExtensions).
1260+
1261+
#### <a name="encoding"></a>Encoding
1262+
1263+
A single encoding definition applied to a single schema property
1264+
1265+
##### Fixed Fields
1266+
Field Name | Type | Description
1267+
---|:---:|---
1268+
<a name="contentType"></a>Content-Type | `string` | **Required.** The content-type to use for encoding a specific property.
1269+
1270+
This object can be extended with [Specification Extensions](#specificationExtensions).
1271+
1272+
##### Encoding Object Examples
1273+
1274+
```yaml
1275+
requestBody:
1276+
content:
1277+
multipart/mixed:
1278+
schema:
1279+
type: object
1280+
properties:
1281+
id:
1282+
# default is text/plain
1283+
type: string
1284+
format: uuid
1285+
address:
1286+
# default is application/json
1287+
type: object
1288+
properties: {}
1289+
historyMetadata:
1290+
# need to declare XML format!
1291+
description: metadata in XML format
1292+
type: object
1293+
properties: {}
1294+
profileImage:
1295+
# default is application/octet-stream, need to declare an image type only!
1296+
type: string
1297+
format: binary
1298+
encoding:
1299+
historyMetadata:
1300+
# require XML content-type in utf-8 encoding
1301+
contentType: application/xml; charset=utf-8
1302+
profileImage:
1303+
# only accept png/jpeg
1304+
contentType: image/png, image/jpeg
1305+
```
11271306

11281307
#### <a name="itemsObject"></a>Items Object
11291308

0 commit comments

Comments
 (0)