Skip to content

Commit 61f9d7e

Browse files
lornajanedarrelmiller
authored andcommitted
Add support for webhooks as a top-level element (OAI#2103)
* Add webhooks as a top-level element to the spec * Add the changes from OAI#2048 and signpost webhooks * Add an example of webhooks * Relocate and expand on webhooks section following feedback * Better wording to describe expectations on API consumers * Clearer wording for why the paths element is here * Update language to make callbacks clearer
1 parent e3c236a commit 61f9d7e

File tree

2 files changed

+87
-6
lines changed

2 files changed

+87
-6
lines changed

examples/v3.1/webhook-example.yaml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
openapi: 3.1.0
2+
info:
3+
title: Webhook Example
4+
version: 1.0.0
5+
paths:
6+
# OpenAPI documents all need a paths element
7+
/pets:
8+
get:
9+
summary: List all pets
10+
operationId: listPets
11+
parameters:
12+
- name: limit
13+
in: query
14+
description: How many items to return at one time (max 100)
15+
required: false
16+
schema:
17+
type: integer
18+
format: int32
19+
responses:
20+
'200':
21+
description: A paged array of pets
22+
content:
23+
application/json:
24+
schema:
25+
$ref: "#/components/schemas/Pets"
26+
27+
webhooks:
28+
# Each webhook needs a name
29+
newPet:
30+
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
31+
post:
32+
requestBody:
33+
description: Information about a new pet in the system
34+
content:
35+
application/json:
36+
schema:
37+
$ref: "#/components/schemas/Pet"
38+
responses:
39+
"200":
40+
description: Return a 200 status to indicate that the data was received successfully
41+
42+
components:
43+
schemas:
44+
Pet:
45+
required:
46+
- id
47+
- name
48+
properties:
49+
id:
50+
type: integer
51+
format: int64
52+
name:
53+
type: string
54+
tag:
55+
type: string
56+
Pets:
57+
type: array
58+
items:
59+
$ref: "#/components/schemas/Pet"
60+
61+

versions/3.1.0.md

+26-6
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ Field Name | Type | Description
193193
<a name="oasInfo"></a>info | [Info Object](#infoObject) | **REQUIRED**. Provides metadata about the API. The metadata MAY be used by tooling as required.
194194
<a name="oasServers"></a>servers | [[Server Object](#serverObject)] | An array of Server Objects, which provide connectivity information to a target server. If the `servers` property is not provided, or is an empty array, the default value would be a [Server Object](#serverObject) with a [url](#serverUrl) value of `/`.
195195
<a name="oasPaths"></a>paths | [Paths Object](#pathsObject) | **REQUIRED**. The available paths and operations for the API.
196+
<a name="oasWebhooks"></a>webhooks | Map[`string`, [Path Item Object](#pathItemObject)] | The incoming webhooks that MAY be received as part of this API and that the API consumer MAY choose to implement. Closely related to the `callbacks` feature, this section describes requests initiated other than by an API call, for example by an out of band registration. The key name is a unique string to refer to each webhook, while the Path Item Object describes a request that may be initiated by the API provider and the expected responses. An [example](../examples/v3.1/webhook-example.yaml) is available.
196197
<a name="oasComponents"></a>components | [Components Object](#componentsObject) | An element to hold various schemas for the specification.
197198
<a name="oasSecurity"></a>security | [[Security Requirement Object](#securityRequirementObject)] | A declaration of which security mechanisms can be used across the API. 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. Individual operations can override this definition.
198199
<a name="oasTags"></a>tags | [[Tag Object](#tagObject)] | A list of tags used by the specification with additional metadata. The order of the tags can be used to reflect on their order by the parsing tools. Not all tags that are used by the [Operation Object](#operationObject) must be declared. The tags that are not declared MAY be organized randomly or based on the tools' logic. Each tag name in the list MUST be unique.
199200
<a name="oasExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation.
200201

202+
201203
This object MAY be extended with [Specification Extensions](#specificationExtensions).
202204

203205
#### <a name="infoObject"></a>Info Object
@@ -1844,6 +1846,8 @@ A map of possible out-of band callbacks related to the parent operation.
18441846
Each value in the map is a [Path Item Object](#pathItemObject) that describes a set of requests that may be initiated by the API provider and the expected responses.
18451847
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.
18461848

1849+
To describe incoming requests from the API provider independent from another API call, use the [`webhooks`](#oasWebhooks) field.
1850+
18471851
##### Patterned Fields
18481852
Field Pattern | Type | Description
18491853
---|:---:|---
@@ -1893,25 +1897,41 @@ $request.body#/successUrls/2 | https://clientdomain.com/medium
18931897
$response.header.Location | https://example.org/subscription/1
18941898

18951899

1896-
##### Callback Object Example
1900+
##### Callback Object Examples
18971901

1898-
The following example shows a callback to the URL specified by the `id` and `email` property in the request body.
1902+
The following example uses the user provided `queryUrl` query string parameter to define the callback URL. This is an example of how to use a callback object to describe a callback that goes with the subscription operation to enable registering for the callback.
18991903

19001904
```yaml
1901-
myWebhook:
1902-
'https://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':
1905+
myCallback:
1906+
'{$request.query.queryUrl}':
19031907
post:
19041908
requestBody:
19051909
description: Callback payload
1906-
content:
1910+
content:
19071911
'application/json':
19081912
schema:
19091913
$ref: '#/components/schemas/SomePayload'
19101914
responses:
19111915
'200':
1912-
description: webhook successfully processed and no retries will be performed
1916+
description: callback successfully processed
19131917
```
19141918

1919+
The following example shows a callback where the server is hard-coded, but the query string parameters are populated from the `id` and `email` property in the request body.
1920+
1921+
```yaml
1922+
transactionCallback:
1923+
'http://notificationServer.com?transactionId={$request.body#/id}&email={$request.body#/email}':
1924+
post:
1925+
requestBody:
1926+
description: Callback payload
1927+
content:
1928+
'application/json':
1929+
schema:
1930+
$ref: '#/components/schemas/SomePayload'
1931+
responses:
1932+
'200':
1933+
description: callback successfully processed
1934+
```
19151935

19161936
#### <a name="exampleObject"></a>Example Object
19171937

0 commit comments

Comments
 (0)