Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 3cc20af

Browse files
authored
Merge pull request OAI#1040 from OAI/issue-1039
Explanation for links confusion, fixes
2 parents 1b9a5c1 + e8f399c commit 3cc20af

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

versions/3.0.md

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,23 +2003,27 @@ The `Link Object` is responsible for defining a possible operation based on a si
20032003

20042004
Field Name | Type | Description
20052005
---|:---:|---
2006-
href | `string` | a relative or absolute URL to a linked resource. This field is mutually exclusive with the `operationId` field.
2007-
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](#operationObject) in the OAS.
2008-
parameters | [Link Parameters Object](#linkParametersObject) | an object representing parameters to pass to an operation as specified with `operationId` or identified via `href`.
2009-
headers | [Headers Object](#headersObject) | an object representing headers to pass to the linked resource. Where conflicts occur between these headers, and those defined in the related operation, these headers override.
2010-
description | `string` | a description of the link, supports [CommonMark syntax](http://spec.commonmark.org/).
2006+
operationRef | `string` | a relative or absolute reference to an OAS operation. This field is mutually exclusive with the `operationId` field, and must point to the fragment of a valid OAS definition
2007+
operationId | `string` | the name of an _existing_, resolvable OAS operation, as defined with a unique `operationId`. This field is mutually exclusive with the `operationRef` field. Relative `operationRef` values MAY be used to locate an existing [Operation Object](#operationObject) in the OAS.
2008+
parameters | [Link Parameters Object](#linkParametersObject) | an object representing parameters to pass to an operation as specified with `operationId` or identified via `operationRef`.
2009+
headers | [Headers Object](#headersObject) | an object representing headers to pass to the linked resource. Where conflicts occur between these headers, and those defined in the related operation, these headers override.
2010+
description | `string` | a description of the link, supports [CommonMark syntax](http://spec.commonmark.org/).
2011+
server | [Server Object](#serverObject) | a server object to be used by the target operation
20112012

20122013
This object can be extended with [Specification Extensions](#specificationExtensions).
20132014

2014-
Locating a linked resource MAY be performed by either a `href` or `operationId`.
2015+
Locating a linked resource MAY be performed by either a `operationRef` or `operationId`.
20152016
In the case of an `operationId`, it MUST be unique and resolved in the scope of the OAS document.
2016-
Because of the potential for name clashes, consider the `href` syntax as the preferred method for specifications with external references.
2017+
Because of the potential for name clashes, consider the `operationRef` syntax as the preferred
2018+
method for specifications with external references.
20172019

20182020
##### <a name="responsePayload"></a>Response Payload Values
20192021

2020-
Payload values are only available in parsable response payloads which match the advertised media type and for media types that can be referenced using a JSON Pointer fragment Id.
2021-
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.
2022-
In cases where a value is required, and a parameter is not supplied, the client MAY choose to not follow the link definition.
2022+
Payload values are only available in parsable response payloads which match the advertised media
2023+
type and for media types that can be referenced using a JSON Pointer fragment Id. In all cases,
2024+
if a value does _not_ exist, the parameter will be considered a `null` value (as opposed to an
2025+
empty value) and _not_ passed as a parameter to the linked resource. In cases where a value is
2026+
required, and a parameter is not supplied, the client MAY choose to not follow the link definition.
20232027

20242028
##### Example
20252029

@@ -2126,51 +2130,46 @@ Can be used in a link like this:
21262130

21272131
```yaml
21282132
Addresses:
2129-
href: '/users/{$request.path.id}/department'
2133+
# the target link operationId
2134+
operationId: getUserAddress
2135+
parameters:
2136+
# get the `id` field from the request path parameter named `id`
2137+
userId: '{$request.path.id}'
21302138
```
21312139
21322140
Where the `$request.path.id` is the value passed in the request to `/users/{id}`.
2133-
For a `id` value of `10101110`, the generated link would be:
2134-
2135-
```yaml
2136-
href: '/users/10101110/department'
2137-
```
21382141

21392142
##### Response Payload Example
21402143

21412144
```yaml
21422145
Addresses:
2143-
href: '/users/{$response.body#/uuid}/address'
2144-
```
2145-
2146-
Where the `$response.uuid` from the example above would yield the target:
2147-
2148-
2149-
```yaml
2150-
href: '/users/df71a505-07bc-458a-a5c0-73c0340d1ec7/address'
2146+
operationId: getUserAddressByUUID
2147+
parameters:
2148+
# get the `id` field from the request path parameter named `id`
2149+
userUuid: '{$response.body#/uuid}'
21512150
```
21522151
21532152
And the array example:
21542153
21552154
```yaml
21562155
ColorSelection:
2157-
href: 'http://colors.my-server.com/colors/{$response.body#/color}'
2156+
operationId: getColorSample
2157+
parameters:
2158+
colorName: '{$response.body#/color}'
21582159
```
21592160
2160-
Would produce the following links:
2161-
2162-
```yaml
2163-
href: 'http://colors.my-server.com/colors/red'
2164-
href: 'http://colors.my-server.com/colors/green'
2165-
href: 'http://colors.my-server.com/colors/blue'
2166-
```
2161+
Would produce three links with the `colorName` of `red`, `green`, and `blue`:
21672162

2168-
As with all links, it is at the clients' discretion to follow them, neither permissions nor the ability to make a successful call to that link is guaranteed solely by the existence of a relationship.
2163+
As with all links, it is at the clients' discretion to follow them, neither
2164+
permissions nor the ability to make a successful call to that link is guaranteed
2165+
solely by the existence of a relationship.
21692166

21702167

21712168
##### Example
21722169

2173-
The example below shows how relationships in the BitBucket API can be represented with the link schema. This example uses `operationId` values to link responses to possible operations.
2170+
The example below shows how relationships in the BitBucket API can be represented
2171+
with the link schema. This example uses `operationId` values to link responses to
2172+
possible operations.
21742173

21752174
```yaml
21762175
paths:
@@ -2343,7 +2342,7 @@ components:
23432342
# executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge
23442343
operationId: mergePullRequest
23452344
parameters:
2346-
username: $response.body#/user/username # Should be $response.author.username?
2345+
username: $response.body#/author/username
23472346
slug: $response.body#/repository/slug
23482347
pid: $response.body#/id
23492348
schemas:
@@ -2374,26 +2373,29 @@ components:
23742373
$ref: '#/components/schemas/user'
23752374
```
23762375

2377-
As references to `operationId` MAY NOT be possible (the `operationId` is an optional value), references MAY also be made through a relative `href`:
2376+
As references to `operationId` MAY NOT be possible (the `operationId` is an optional
2377+
value), references MAY also be made through a relative `operationRef`:
23782378

23792379
```yaml
23802380
components:
23812381
links:
23822382
UserRepositories:
23832383
# returns array of '#/components/schemas/repository'
2384-
href: '/2.0/repositories/{$response.body#/username}'
2384+
operationRef: '#paths~12.0~1repositories~1{$response.body#/username}'
23852385
```
23862386

2387-
or an absolute `href`:
2387+
or an absolute `operationRef`:
23882388

23892389
```yaml
23902390
components:
23912391
links:
23922392
UserRepositories:
23932393
# returns array of '#/components/schemas/repository'
2394-
href: 'https://na2.gigantic-server.com/2.0/repositories/{$response.body#/username}'
2394+
href: 'https://na2.gigantic-server.com/#/paths/~12.0~1repositories~1{$response.body#/username}'
23952395
```
23962396

2397+
Note that in the use of `operationRef`, the _escaped forward-slash_ is necessary when
2398+
using JSON references.
23972399

23982400
#### <a name="linkParametersObject"></a>Link Parameters Object
23992401
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.

0 commit comments

Comments
 (0)