Skip to content

Commit 4d322ec

Browse files
authored
Merge pull request #891 from OAI/dm/callback-review
Callback review and preliminary message expression syntax
2 parents 1a0248c + d4e2cfe commit 4d322ec

File tree

1 file changed

+106
-41
lines changed

1 file changed

+106
-41
lines changed

versions/3.0.md

Lines changed: 106 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ Field Name | Type | Description
589589
<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).
590590
<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. In other cases where the HTTP spec is vague, `requestBody` shall be ignored by consumers.
591591
<a name="operationResponses"></a>responses | [Responses Object](#responsesObject) | **Required.** The list of possible responses as they are returned from executing this operation.
592-
<a name="operationCallbacks"></a>callback responses | [Callback Responses Object](#callbackObject) | The list of possible callback responses as they are returned from executing this operation.
592+
<a name="operationCallbacks"></a>callbacks | [Callbacks Object](#callbacksObject) | The list of possible callbacks as they are returned from executing this operation.
593593
<a name="operationDeprecated"></a>deprecated | `boolean` | Declares this operation to be deprecated. Usage of the declared operation should be refrained. Default value is `false`.
594594
<a name="operationSecurity"></a>security | [[Security Requirement Object](#securityRequirementObject)] | A declaration of which security mechanisms can be used for this operation. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request. This definition overrides any declared top-level [`security`](#oasSecurity). To remove a top-level security declaration, an empty array can be used.
595595
<a name="operationItemServer"></a>servers | [Server Object](#serverObject) | An alternative `server` array to service this operation. If an alternative `server` object is specified at the Path Item Object or Root level, it will be overridden by this value.
@@ -1493,17 +1493,62 @@ Response with no return value:
14931493
description: object created
14941494
```
14951495

1496-
#### <a name="callbackObject"></a>Callback Object
1496+
#### <a name="callbacksObject"></a>Callbacks Object
14971497

1498-
A container for possible out-of band callbacks from an operation. A callback may be returned from an operation, calling back to the path specified in the operation object.
1498+
A map of possible out-of band callbacks related to the parent operation.
1499+
Each value in the map is an [Operation Object](#operationObject) that describes a request that may be initiated by the API provider and the expected responses.
1500+
The key value used to identify the callback object is an expression, evaluated at runtime, that identifies a URL to use for the callback operation.
14991501

15001502
##### Patterned Fields
15011503
Field Pattern | Type | Description
15021504
---|:---:|---
1503-
<a name="responseName"></a>Callback name | [Callback Operation Object](#operationObject) <span>&#124;</span> [Operation Object](#operationObject) | An operation object used to define a callback payload structure
1505+
<a name="callbackName"></a>Callback name | [Callback Operation Object](#operationObject) <span>&#124;</span> [Operation Object](#operationObject) | An Operation Object used to define a callback request and expected responses
15041506

15051507
This object can be extended with [Specification Extensions](#specificationExtensions).
15061508

1509+
##### Key Expression
1510+
1511+
The key used to identify the callback object is a variable expression that can be evaluated in the context of a runtime HTTP request/response to identify the URL to be used for the callback request.
1512+
A simple example might be `$request.body#/url`.
1513+
However, using [variable substition](#variableSubstition) syntax the complete HTTP message can be accessed.
1514+
This includes accessing any part of a body that can be accessed using a JSON Pointer [RFC6901](https://tools.ietf.org/html/rfc6901).
1515+
1516+
1517+
For example, given the following HTTP request:
1518+
1519+
```http
1520+
POST /subscribe/myevent?queryUrl=http://clientdomain.com/stillrunning HTTP/1.1
1521+
Host: example.org
1522+
Content-Type: application/json
1523+
Content-Length: 123
1524+
1525+
{
1526+
"failedUrl" : "http://clientdomain.com/failed"
1527+
"successUrls : [
1528+
"http://clientdomain.com/fast",
1529+
"http://clientdomain.com/medium",
1530+
"http://clientdomain.com/slow"
1531+
]
1532+
}
1533+
1534+
201 Created
1535+
Location: http://example.org/subscription/1
1536+
1537+
```
1538+
1539+
Here are the examples of how the various expressions evaluate, assuming a the callback operation has a path parameter named `eventType` and a query parameter named `queryUrl`.
1540+
1541+
Expression | Value
1542+
---|:---
1543+
$url | http://example.org/subscribe/myevent?queryUrl=http://clientdomain.com/stillrunning
1544+
$method | POST
1545+
$request.path.eventType | myevent
1546+
$request.query.queryUrl | http://clientdomain.com/stillrunning
1547+
$request.header.content-Type | application/json
1548+
$request.body#/failedUrl | http://clientdomain.com/stillrunning
1549+
$request.body#/successUrls/2 | http://clientdomain.com/medium
1550+
$response.header.Location | http://example.org/subscription/1
1551+
15071552

15081553
##### Callback Object Example
15091554

@@ -1512,12 +1557,14 @@ A callback to the URL specified by the `url` parameter in the request
15121557

15131558
```yaml
15141559
myWebhook:
1515-
'$request.url':
1560+
'$request.body#/url':
15161561
post:
1517-
body:
1518-
name: postResponse
1519-
schema:
1520-
$ref: '#/definitions/SomePayload'
1562+
requestBody:
1563+
description: Callback payload
1564+
content:
1565+
'application/json'
1566+
schema:
1567+
$ref: '#/components/definitions/SomePayload'
15211568
responses:
15221569
200:
15231570
description: webhook successfully processed an no retries will be performed
@@ -1631,11 +1678,11 @@ The `Link Object` is responsible for defining a possible operation based on a si
16311678

16321679
Field Name | Type | Description
16331680
---|:---:|---
1634-
href | url | a relative or absolute URL to a linked resource. This field is mutually exclusive with the `operationId` field.
1635-
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.
1636-
parameters | Link Parameters Object | an Object representing parameters to pass to an operation as specified with `operationId` or identified via `href`.
1637-
headers | Link Headers Object | an Object representing headers to pass to the linked resource.
1638-
description | string | a description of the link, supports [CommonMark syntax](http://spec.commonmark.org/).
1681+
href | `string` | a relative or absolute URL to a linked resource. This field is mutually exclusive with the `operationId` field.
1682+
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.
1683+
parameters | [Link Parameters Object](#linkParameters) | an Object representing parameters to pass to an operation as specified with `operationId` or identified via `href`.
1684+
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.
1685+
description | `string` | a description of the link, supports [CommonMark syntax](http://spec.commonmark.org/).
16391686

16401687
This object can be extended with [Specification Extensions](#specificationExtensions).
16411688

@@ -1645,7 +1692,7 @@ Because of the potential for name clashes, consider the `href` syntax as the pre
16451692

16461693
#### <a name="responsePayload"></a>Response Payload Values
16471694

1648-
Payload values are only available in parseable response payloads which match the advertised media-type.
1695+
Payload values are only available in parseable response payloads which match the advertised media-type and for media-types that can be referenced using a JSON Pointer fragment Id.
16491696
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.
16501697
In cases where a value is required, and a parameter is not supplied, the client _may_ choose to not follow the link definition.
16511698

@@ -1688,23 +1735,41 @@ color: ["red", "green", "blue"]
16881735
The variables generated can be used in locations prescribed by the definition.
16891736

16901737

1691-
### Variable substitution
1738+
### <a name="variableSubstition"></a>Variable substitution
16921739
In all cases, _variables_ from request and responses may be substituted for link generation.
1693-
The table below designates the source of the substitution value and the syntax for accessing it:
1740+
The table below provides examples of variable expressions and examples of their use in a value:
16941741

1695-
Source Location | reference identifier | example value | example reference | notes
1696-
---|:---|:---|:---|:---
1742+
Source Location | variable expression | example reference | notes
1743+
---|:---|:---|:---
16971744
HTTP Method | `$method` | `/users/{$method}` | The allowable values for the `$method` will be those for the HTTP operation
1698-
Requested content type | `$accepts` | `/users/3?format={$accepts}` |
1699-
Request parameter | `$request` | `/users/{$request.id}` | Request parameters must be declared in the `parameters` section for the operation or they cannot be used in substitution. This includes request headers
1700-
Request body | `$requestBody` | `/users/{$requestBody.user.uuid}` | For operations which accept payloads, references may be made to portions of the `requestBody` or the entire body itself
1745+
Requested content type | `$request.header.accept` | `/users/3?format={$request.header.accept}` |
1746+
Request parameter | `$request.path.id` | `/users/{$request.path.id}` | Request parameters must be declared in the `parameters` section for the operation or they cannot be used in substitution. This includes request headers
1747+
Request body | `$request.body` | `/users/{$request.body#/user/uuid}` | For operations which accept payloads, references may be made to portions of the `requestBody` or the entire body itself
17011748
Request URL | `$url` | `/track?url={$url}` |
1702-
Response value | `$response` | `{$response.uuid}` | Only the payload in the response can be accessed with the `$response` syntax
1703-
Response header | `$responseHeader` | `{$responseHeader.Server}` | Single header values only are available.
1749+
Response value | `$response.body` | `{$response.body#/uuid}` | Only the payload in the response can be accessed with the `$response` syntax.
1750+
Response header | `$response.header` | `{$response.header.Server}` | Single header values only are available
17041751

17051752
From the request, the `parameter`s used in calling the operation are made available through the `$request` syntax.
17061753
For responses, the response payload may be used with the `$response` syntax.
1707-
For both requests and responses, values will be substituted in the link in sections designated with the `$request` or `$response` keyword, surrounded by curly brackets `{}`.
1754+
For both requests and responses, values will be substituted in the link in sections designated with a variable expression, surrounded by curly brackets `{}`.
1755+
1756+
The variable expression is defined by the following [ABNF](https://tools.ietf.org/html/rfc5234) syntax
1757+
1758+
```
1759+
expression = ( "$url" | "$method" | "$request." [ source ] | "$response." [ source ])
1760+
source = ( header-reference | query-reference | path-reference | body-reference )
1761+
header-reference = "header." token
1762+
query-reference = "query." name
1763+
path-reference = "path." name
1764+
body-reference = "body#" fragment
1765+
fragment = a JSON Pointer [RFC 6901](https://tools.ietf.org/html/rfc6901)
1766+
name = *( char )
1767+
char = as per RFC [7159](https://tools.ietf.org/html/rfc7159#section-7)
1768+
token = as per RFC [7230](https://tools.ietf.org/html/rfc7230#section-3.2.6)
1769+
```
1770+
1771+
The `name` identifier is case-sensitive, whereas `token` is not.
1772+
17081773
17091774
### Request parameter example
17101775
Computing a link from a request operation like such:
@@ -1736,10 +1801,10 @@ Can be used in a link like this:
17361801

17371802
```yaml
17381803
Addresses:
1739-
href: '/users/{$request.id}/department'
1804+
href: '/users/{$request.path.id}/department'
17401805
```
17411806
1742-
Where the `$request.id` is the value passed in the request to `/users/{id}`.
1807+
Where the `$request.path.id` is the value passed in the request to `/users/{id}`.
17431808
For a `id` value of `10101110`, the generated link would be:
17441809

17451810
```yaml
@@ -1750,7 +1815,7 @@ href: '/users/10101110/department'
17501815

17511816
```yaml
17521817
Addresses:
1753-
href: '/users/{$response.uuid}/address'
1818+
href: '/users/{$response.body#/uuid}/address'
17541819
```
17551820

17561821
Where the `$response.uuid` from the example above would yield the target:
@@ -1764,7 +1829,7 @@ And the array example:
17641829

17651830
```yaml
17661831
ColorSelection:
1767-
href: 'http://colors.my-server.com/colors/{$response.color}'
1832+
href: 'http://colors.my-server.com/colors/{$response.body#/color}'
17681833
```
17691834

17701835
Would produce the following links:
@@ -1922,26 +1987,26 @@ components:
19221987
# returns array of '#/components/definitions/repository'
19231988
operationId: getRepositoriesByOwner
19241989
parameters:
1925-
username: $response.username
1990+
username: $response.body#/username
19261991
UserRepository:
19271992
# returns '#/components/definitions/repository'
19281993
operationId: getRepository
19291994
parameters:
1930-
username: $response.owner.username
1931-
slug: $response.slug
1995+
username: $response.body#/owner/username
1996+
slug: $response.body#/slug
19321997
RepositoryPullRequests:
19331998
# returns '#/components/definitions/pullrequest'
19341999
operationId: getPullRequestsByRepository
19352000
params:
1936-
username: $response.owner.username
1937-
slug: $response.slug
2001+
username: $response.body#/owner/username
2002+
slug: $response.body#/slug
19382003
PullRequestMerge:
19392004
# executes /2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge
19402005
operationId: mergePullRequest
19412006
parameters:
1942-
username: $response.user.username # Should be $response.author.username?
1943-
slug: $response.repository.slug
1944-
pid: $response.id
2007+
username: $response.body#/user/username # Should be $response.author.username?
2008+
slug: $response.body#/repository/slug
2009+
pid: $response.body#/id
19452010
definitions:
19462011
user:
19472012
type: object
@@ -1977,7 +2042,7 @@ components:
19772042
links:
19782043
UserRepositories:
19792044
# returns array of '#/components/definitions/repository'
1980-
href: '/2.0/repositories/{$response.username}'
2045+
href: '/2.0/repositories/{$response.body#/username}'
19812046
```
19822047

19832048
or an absolute `href`:
@@ -1987,11 +2052,11 @@ components:
19872052
links:
19882053
UserRepositories:
19892054
# returns array of '#/components/definitions/repository'
1990-
href: 'https://na2.gigantic-server.com/2.0/repositories/{$response.username}'
2055+
href: 'https://na2.gigantic-server.com/2.0/repositories/{$response.body#/username}'
19912056
```
19922057

19932058

1994-
### Link Parameters
2059+
### <a name="linkParameters"></a>Link Parameters
19952060
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.
19962061
Many operations require parameters to be passed, and these may be dynamic depending on the response itself.
19972062

@@ -2019,7 +2084,7 @@ components:
20192084
UserCommitHistory:
20202085
operationId: userCommitHistory
20212086
parameters:
2022-
username: $response.user.username
2087+
username: $response.body#/user/username
20232088
page: 0
20242089
```
20252090

0 commit comments

Comments
 (0)