You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versions/3.0.md
+176-28
Original file line number
Diff line number
Diff line change
@@ -145,13 +145,11 @@ By convention, the OpenAPI Specification (OAS) file is named `openapi.json` or `
145
145
Primitive data types in the OAS are based on the types supported by the [JSON-Schema Draft 4](http://json-schema.org/latest/json-schema-core.html#anchor8).
146
146
Models are described using the [Schema Object](#schemaObject) which is a subset of JSON Schema Draft 4.
147
147
148
-
An additional primitive data type `"file"` is used by the [Parameter Object](#parameterObject) and the [Response Object](#responseObject) to set the parameter type or the response as being a file.
149
-
150
148
<aname="dataTypeFormat"></a>Primitives have an optional modifier property `format`.
151
149
OAS uses several known formats to more finely define the data type being used.
152
150
However, the `format` property is an open `string`-valued property, and can have any value to support documentation needs.
153
151
Formats such as `"email"`, `"uuid"`, etc., can be used even though they are not defined by this specification.
154
-
Types that are not accompanied by a `format` property follow their definition from the JSON Schema (except for `file` type which is defined above).
152
+
Types that are not accompanied by a `format` property follow their definition from the JSON Schema.
155
153
The formats defined by the OAS are:
156
154
157
155
@@ -529,7 +527,7 @@ This object can be extended with [Specification Extensions](#specificationExtens
529
527
"items": {
530
528
"type": "string"
531
529
},
532
-
"style": "comma-delimited"
530
+
"style": "commaDelimited"
533
531
}
534
532
]
535
533
}
@@ -580,7 +578,7 @@ Field Name | Type | Description
580
578
<a name="operationExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this operation.
581
579
<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.
582
580
<a name="operationParameters"></a>parameters | [[Parameter Object](#parameterObject) <span>|</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>|</span> [Reference Object](#referenceObject)] | The request body applicable for this operation.
581
+
<a name="operationRequestBody"></a>requestBody | [[Request Body Object](#requestBodyObject) <span>|</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. In other cases where the HTTP spec is vague, `requestBody` shall be ignored by consumers.
584
582
<a name="operationResponses"></a>responses | [Responses Object](#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation.
585
583
<a name="operationCallbacks"></a>callback responses | [Callback Responses Object](#callbackObject) | The list of possible callback responses as they are returned from executing this operation.
586
584
<a name="operationDeprecated"></a>deprecated | `boolean` | Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`.
@@ -742,7 +740,7 @@ There are four possible parameter types.
742
740
Field Name | Type | Description
743
741
---|:---:|---
744
742
<a name="parameterName"></a>name | `string` | **Required.** The name of the parameter. Parameter names are *case sensitive*. <ul><li>If [`in`](#parameterIn) is `"path"`, the `name` field MUST correspond to the associated path segment from the [path](#pathsPath) field in the [Paths Object](#pathsObject). See [Path Templating](#pathTemplating) for further information.<li>For all other cases, the `name` corresponds to the parameter name used based on the [`in`](#parameterIn) property.</ul>
745
-
<a name="parameterIn"></a>in | `string` | **Required.** The location of the parameter. Possible values are "query", "header", "path", "formData" or "cookie".
743
+
<a name="parameterIn"></a>in | `string` | **Required.** The location of the parameter. Possible values are "query", "header", "path" or "cookie".
746
744
<a name="parameterDescription"></a>description | `string` | A brief description of the parameter. This could contain examples of use. [CommonMark syntax](http://spec.commonmark.org/) can be used for rich text representation.
747
745
<a name="parameterRequired"></a>required | `boolean` | Determines whether this parameter is mandatory. If the parameter is [`in`](#parameterIn) "path", this property is **required** and its value MUST be `true`. Otherwise, the property MAY be included and its default value is `false`.
748
746
<a name="parameterDeprecated"></a> deprecated | `boolean` | Specifies that a parameter is deprecated and should be transitioned out of usage.
@@ -890,28 +888,6 @@ style: form
890
888
explode: true
891
889
```
892
890
893
-
A form data with file type for a file upload:
894
-
```json
895
-
{
896
-
"name": "avatar",
897
-
"in": "formData",
898
-
"description": "The avatar of the user",
899
-
"required": true,
900
-
"schema": {
901
-
"type": "file"
902
-
}
903
-
}
904
-
```
905
-
906
-
```yaml
907
-
name: avatar
908
-
in: formData
909
-
description: The avatar of the user
910
-
required: true
911
-
schema:
912
-
type: file
913
-
```
914
-
915
891
#### <a name="requestBodyObject"></a>Request Body Object
916
892
917
893
Describes a single request body.
@@ -1124,6 +1100,178 @@ application/json:
1124
1100
1125
1101
```
1126
1102
1103
+
##### Considerations for file uploads
1104
+
1105
+
In contrast with the 2.0 specification, describing `file` input/output content in OpenAPI is
1106
+
described with the same semantics as any other schema type. Specifically:
1107
+
1108
+
```yaml
1109
+
# content transferred with base64 encoding
1110
+
schema:
1111
+
type: string
1112
+
format: base64
1113
+
1114
+
# content transfered in binary (octet-stream):
1115
+
schema:
1116
+
type: string
1117
+
format: binary
1118
+
```
1119
+
1120
+
Note that the above examples apply to either input payloads (i.e. file uploads) or response payloads.
1121
+
1122
+
A `requestBody` example for submitting a file in a `POST` operation therefore may look like the following:
1123
+
1124
+
```yaml
1125
+
requestBody:
1126
+
# any media type is accepted, functionally equivalent to `*/*`
1127
+
application/octet-stream:
1128
+
content:
1129
+
schema:
1130
+
# a binary file of any type
1131
+
type: string
1132
+
format: binary
1133
+
```
1134
+
1135
+
In addition, specific media types may be specified:
1136
+
1137
+
```yaml
1138
+
# multiple, specific media types may be specified:
1139
+
requestBody:
1140
+
# a binary file of type png or jpeg
1141
+
content:
1142
+
'image/png, image/jpeg':
1143
+
schema:
1144
+
type: string
1145
+
format: binary
1146
+
```
1147
+
1148
+
##### Support for x-www-form-urlencoded request bodies
1149
+
1150
+
To submit content using form url encoding via RFC 1866, the following
1151
+
definition may be used:
1152
+
1153
+
```yaml
1154
+
requestBody:
1155
+
content:
1156
+
x-www-form-urlencoded:
1157
+
schema:
1158
+
type: object
1159
+
properties:
1160
+
id:
1161
+
type: string
1162
+
format: uuid
1163
+
address:
1164
+
# complex types are stringified to support rfc1866
1165
+
type: object
1166
+
properties: {}
1167
+
```
1168
+
1169
+
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.
1170
+
1171
+
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`.
1172
+
1173
+
##### Special Considerations for `mutlipart` content
1174
+
1175
+
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.
1176
+
1177
+
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/*`:
1178
+
1179
+
* If the property is a primitive, or an array of primitive values, the default Content-Type is `text/plain`
1180
+
* If the property is complex, or an array of complex values, the default Content-Type is `application/json`
1181
+
* 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`
1182
+
1183
+
1184
+
Examples:
1185
+
1186
+
```yaml
1187
+
requestBody:
1188
+
content:
1189
+
multipart/form-data:
1190
+
schema:
1191
+
type: object
1192
+
properties:
1193
+
id:
1194
+
type: string
1195
+
format: uuid
1196
+
address:
1197
+
# default Content-Type for objects is `application/json`
1198
+
type: object
1199
+
properties: {}
1200
+
profileImage:
1201
+
# default Content-Type for string/binary is `application/octet-stream`
1202
+
type: string
1203
+
format: binary
1204
+
children:
1205
+
# default Content-Type for arrays is based on the `inner` type (text/plain here)
1206
+
type: array
1207
+
items:
1208
+
type: string
1209
+
addresses:
1210
+
# default Content-Type for arrays is based on the `inner` type (object shown, so `application/json` in this example)
1211
+
type: array
1212
+
items:
1213
+
type: '#/definitions/Address'
1214
+
```
1215
+
1216
+
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/*` and `x-www-form-urlencoded` request bodies.
1217
+
1218
+
#### <a name="encodingObject"></a>Encoding Object
1219
+
1220
+
An object representing multipart region encoding for `requestBody` objects
1221
+
1222
+
##### Patterned Fields
1223
+
Field Pattern | Type | Description
1224
+
---|:---:|---
1225
+
<a name="encodingObjectProperty"></a>The property to apply encoding to | [Encoding Property](#encodingProperty) <span>|</span> [Encoding](#encoding) | The field name to apply special encoding attributes to. This field must exist in the schema as a property.
1226
+
1227
+
#### <a name="encoding"></a>Encoding
1228
+
1229
+
A single encoding definition applied to a single schema property
1230
+
1231
+
##### Fixed Fields
1232
+
Field Name | Type | Description
1233
+
---|:---:|---
1234
+
<a name="contentType"></a>contentType | `string` | **Required.** The content-type to use for encoding a specific property.
1235
+
<a name="headers"></a>Headers | `object` | A string map allowing additional information to be provided as headers, for example `Content-Disposition`. Note `Content-Type` is described separately and will be ignored from this section.
1236
+
<a name="style"></a>Style | `string` | The content-type to use for encoding a specific property. See (#parameterContent) for details on the `style` property
1237
+
<a name="explode"></a>explode | `boolean` | When this is true, property values of type `array` or `object` generate seperate parameters for each value of the array, or key-value-pair of the map. For other types of properties this property has no effect. The default value is false.
1238
+
1239
+
This object can be extended with [Specification Extensions](#specificationExtensions).
1240
+
1241
+
##### Encoding Object Examples
1242
+
1243
+
```yaml
1244
+
requestBody:
1245
+
content:
1246
+
multipart/mixed:
1247
+
schema:
1248
+
type: object
1249
+
properties:
1250
+
id:
1251
+
# default is text/plain
1252
+
type: string
1253
+
format: uuid
1254
+
address:
1255
+
# default is application/json
1256
+
type: object
1257
+
properties: {}
1258
+
historyMetadata:
1259
+
# need to declare XML format!
1260
+
description: metadata in XML format
1261
+
type: object
1262
+
properties: {}
1263
+
profileImage:
1264
+
# default is application/octet-stream, need to declare an image type only!
0 commit comments