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
+341-1Lines changed: 341 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -938,7 +938,7 @@ default:
938
938
```
939
939
940
940
#### <a name="responseObject"></a>Response Object
941
-
Describes a single response from an API Operation.
941
+
Describes a single response from an API Operation, including design-time, static `links` to operations based on the response.
942
942
943
943
##### Fixed Fields
944
944
Field Name | Type | Description
@@ -947,6 +947,8 @@ Field Name | Type | Description
947
947
<a name="responseSchema"></a>schema | [Schema Object](#schemaObject) | A definition of the response structure. It can be a primitive, an array or an object. If this field does not exist, it means no content is returned as part of the response. As an extension to the [Schema Object](#schemaObject), its root `type` value may also be `"file"`. This SHOULD be accompanied by a relevant `produces` mime-type.
948
948
<a name="responseHeaders"></a>headers | [Headers Object](#headersObject) | A list of headers that are sent with the response.
949
949
<a name="responseExamples"></a>examples | [Example Object](#exampleObject) | An example of the response message.
950
+
<a name="responseLinks"></a>links | [Links Object](#linksObject) | An object representing operations related to the response payload.
951
+
950
952
951
953
##### Patterned Objects
952
954
@@ -1123,6 +1125,344 @@ application/json:
1123
1125
breed: Mixed
1124
1126
```
1125
1127
1128
+
#### <a name="linksObject"></a>Links Object
1129
+
The links object represents a set of possible design-time links for a response. The presence of a link does not guarantee the caller's ability to successfully call invoke it, rather it provides a known relationship and traversal mechanism between responses and other operations.
1130
+
1131
+
As opposed to _dynamic_ links--that is, links provided **in** the response payload, the OAS linking mechanism does not require that link information be provided in a specific response format at runtime.
1132
+
1133
+
For computing links, and providing instructions to execute them, a mechanism is defined for accessing values in a response and using them as variables while invoking the linked operation.
1134
+
1135
+
Field Name | Type | Description
1136
+
---|:---:|---
1137
+
<a name="referenceRef"></a>$ref | `string` | If present, a reference to another Links Object. Note, the presence of `$ref` in the Links Object will cause all _Patterned Objects_ to be ignored.
1138
+
1139
+
Field Pattern | Type | Description
1140
+
---|:---:|---
1141
+
<a name="linkName"></a>link name | [Link Object](#linkObject) | A short name for the link, following the naming constraints of the <a href="#definitionsName">definitions name</a>. The link shall reference a single Link Object, or a JSON Reference to a single link object
1142
+
1143
+
1144
+
### Link Object
1145
+
The `Link Object` is responsible for defining a possible operation based on a single response.
1146
+
1147
+
Field Name | Type | Description
1148
+
--- | :---: | ---
1149
+
href | url | a relative or absolute URL to a linked resource. This field is mutually exclusive with the `operationId` field.
1150
+
operationId| string | the name of an _existing_, resolvable OAS operation, as defined with a unique `operationId`. This field is mutually exclusive with the `href` field. Relative `href` values _may_ be used to locate an existing Operation Object in the OAS.
1151
+
parameters | Link Parameters Object | an Object representing parameters to pass to an operation as specified with `operationId` or identified via `href`.
1152
+
description | string | a description of the link, supports GFM.
Payload values are only available in parseable response payloads which match the advertised media-type. In all cases, if a value does _not_ exist, the parameter will be considered a `null` value (as opposed to an empty value) and _not_ passed as a parameter to the linked resource. In cases where a value is required, and a parameter is not supplied, the client _may_ choose to not follow the link definition.
1157
+
1158
+
### Example
1159
+
1160
+
Response payload:
1161
+
```json
1162
+
{
1163
+
"id": "df71a505-07bc-458a-a5c0-73c0340d1ec7",
1164
+
"firstname": "Ash",
1165
+
"lastname": "Williams"
1166
+
}
1167
+
```
1168
+
1169
+
Payload Variables:
1170
+
```yaml
1171
+
id: df71a505-07bc-458a-a5c0-73c0340d1ec7
1172
+
firstname: Ash
1173
+
lastname: Williams
1174
+
missingValue: null
1175
+
```
1176
+
1177
+
In situations where variables appear in an array, an array of variables will be extracted. For example:
1178
+
1179
+
```json
1180
+
[
1181
+
{ "color": "red" },
1182
+
{ "color": "green" },
1183
+
{ "color": "blue" }
1184
+
]
1185
+
```
1186
+
1187
+
will be extracted as such:
1188
+
1189
+
```json
1190
+
color: ["red", "green", "blue"]
1191
+
```
1192
+
1193
+
The variables generated can be used in locations prescribed by the definition.
1194
+
1195
+
1196
+
### Variable substitution
1197
+
In all cases, _variables_ identified in the response payload may be substitued **only** in locations prescribed in the link definitions. All such locations are prefixed by a `$response` keyword and surrounded by curly brackets `{}`.
1198
+
1199
+
### Example
1200
+
Computing a link from a response object is performed as follows:
1201
+
1202
+
```yaml
1203
+
Addresses:
1204
+
href: /users/{$response.id}/address
1205
+
```
1206
+
1207
+
Where the `$response.id` from the example above would yield the target:
As with all links, it at the the clients' discretion to follow them, and permissions and the existence of a value is not guaranteed soley by the existence of a link relationship. [**I assume you mean that the existance of the link relationship does not guarantee a successful response from the call**]
1229
+
1230
+
1231
+
### Example
1232
+
1233
+
The example below shows how relationships in the BitBucket API can be represented with the proposed OAI link scheme. This example uses `operationId` values to link responses to possible operations.
1234
+
1235
+
```yaml
1236
+
paths:
1237
+
/2.0/users/{username}:
1238
+
get:
1239
+
operationId: getUserByName
1240
+
parameters:
1241
+
- name: username
1242
+
type: string
1243
+
in: path
1244
+
required: true
1245
+
responses:
1246
+
200:
1247
+
description: The User
1248
+
schema:
1249
+
$ref: '#/components/definitions/user'
1250
+
links:
1251
+
userRepositories:
1252
+
$ref: '#/components/links/UserRepositories'
1253
+
/2.0/repositories/{username}:
1254
+
get:
1255
+
operationId: getRepositoriesByOwner
1256
+
parameters:
1257
+
- name: username
1258
+
type: string
1259
+
in: path
1260
+
required: true
1261
+
responses:
1262
+
200:
1263
+
description: repositories owned by the supplied user
Using the `operationId` to reference an operation in the definition has many benefits, including the ability to define media-type options, security requirements, response and error payloads. Many operations require parameters to be passed, and these may be dynamic depending on the response itself.
1436
+
1437
+
To specify parameters required by the operation, we can use a **Link Parameters Object**. This object contains parameter names along with static or dynamic valus:
1438
+
1439
+
```yaml
1440
+
paths:
1441
+
/user/{username}: # ...
1442
+
/user/{username}/commits:
1443
+
get:
1444
+
operationId: userCommitHistory
1445
+
parameters:
1446
+
- name: username
1447
+
in: path
1448
+
type: string
1449
+
required: true
1450
+
- name: page
1451
+
type: integer
1452
+
format: int32
1453
+
required: true
1454
+
responses: { ... }
1455
+
components:
1456
+
links:
1457
+
UserCommitHistory:
1458
+
operationId: userCommitHistory
1459
+
parameters:
1460
+
username: $response.user.username
1461
+
page: 0
1462
+
```
1463
+
1464
+
In the above, the link for `UserCommitHistory` points to the operation `getUserCommitHistory`, and passes the `username` value from the response payload as well as the static scalar value `0`.
0 commit comments