forked from ivankahl/asyncapi-food-delivery-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asyncapi.yaml
202 lines (201 loc) · 7.29 KB
/
asyncapi.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
asyncapi: 2.6.0
info:
title: Food Delivery API
version: 1.0.0
description: Real-time API that lets you place orders for food at resutarants and track the progress of the meal.
externalDocs:
url: https://example.com
servers:
dev:
url: "ws://localhost:3000"
protocol: ws
channels:
/order:
publish:
operationId: publish
summary: Receive messages from the Food Tracking API.
message:
$ref: "#/components/messages/publish"
subscribe:
operationId: subscribe
summary: Place a new order and subscribe to updates on the order's progress.
message:
$ref: "#/components/messages/placeOrder"
components:
messages:
publish:
name: publish
summary: >
Responses that can be returned by the server after an order is placed.
description: >
The following messages can be returned by the server after an order is placed. These messages contain information related to the WebSocket connection and order status.
payload:
anyOf:
- $ref: "#/components/schemas/orderStatusUpdate"
- $ref: "#/components/schemas/closeConnection"
- $ref: "#/components/schemas/openConnection"
examples:
- name: New Connection Example
summary: Example message sent by the server as soon as the client connects.
payload:
messageType: open_connection
message: You're connected. Place an order to start receiving real-time status updates.
- name: Order Placed Example
summary: Example message that is sent by the server as soon as the client places a new order.
payload:
messageType: status_update
status: placed
eta: "2023-04-01T14:12:00Z"
- name: Order Picked Up Example
summary: Example message sent by the server when the driver picks up the order from the restaurant.
payload:
messageType: status_update
status: out_for_delivery
eta: "2023-04-01T14:08:00Z"
- name: Connection Closed Example
summary: Example message that is sent by the server when the order is delivered and the connection with the client is about to close.
payload:
messageType: close_connection
message: Order delivered successfully.
placeOrder:
name: placeOrder
summary: Places a new food order and subscribes to status updates.
description: Message containing the details for a new order to be placed. Once the order is placed, the server will send back order status updates as they happen.
payload:
$ref: "#/components/schemas/placeOrder"
examples:
- name: Simple Order
summary: Example order message sent by the client to the server to place a new order.
payload:
restaurant: "WrapKing"
deliveryAddress:
addressLine1: 11 5th Avenue, Brooklyn
city: New York
postalCode: NY 11215
countryCode: US
items:
- name: "Crispy Chicken Wrap"
quantity: 1
- name: Complex Order
summary: Example of a more complex order message sent by the client to the server to place a new order.
payload:
restaurant: "Subzero"
deliveryAddress:
addressLine1: 189 President Street, Brooklyn
city: New York
postalCode: NY 11215
countryCode: US
items:
- name: "Chilli Hotdog"
quantity: 2
- name: "Coke"
quantity: 1
- name: "Sparkling Water"
quantity: 2
schemas:
address:
description: Object that stores address details for various purposes such as the delivery address.
type: object
properties:
addressLine1:
description: Address line 1 for the address.
type: string
addressLine2:
description: Address Line 2 for the address if necessary.
type: string
city:
description: The name of the city the address is in.
type: string
postalCode:
description: Postal code for the address.
type: string
countryCode:
description: Two-character country code for the address.
type: string
required:
- addressLine1
- postalCode
- countryCode
orderItem:
description: Contains the individual order items in an order.
type: object
properties:
name:
description: The name of the menu item to order.
type: string
quantity:
description: How much to order of this particular menu item.
type: number
minimum: 1
required:
- name
- quantity
placeOrder:
description: Object sent to place a new order.
type: object
properties:
restaurant:
description: The name of the restaurant to order from.
type: string
deliveryAddress:
description: The address where the order should be delivered.
type: object
$ref: "#/components/schemas/address"
items:
description: An array of items that should be ordered from the restaurant.
type: array
items:
$ref: "#/components/schemas/orderItem"
required:
- restaurant
- deliveryAddress
- items
orderStatusUpdate:
description: Message sent by the server to the client containing updates about the order. This message gets sent everytime the order status changes.
type: object
properties:
orderId:
description: The ID used to identify the order.
type: integer
messageType:
description: Specifies that the message is an "status_update" message.
const: "status_update"
status:
description: The order's new status.
type: string
enum:
- "placed"
- "preparing"
- "order_ready"
- "out_for_delivery"
- "delivered"
eta:
description: The estimated arrival time for the delivery. Only returned if it can be calculated.
type: string
format: date-time
required:
- orderId
- messageType
- status
openConnection:
description: Message that gets sent when a client connects. It instructs the client to send an order.
type: object
properties:
messageType:
description: Specifies that the message is a `"open_connection"` message.
type: string
const: "open_connection"
message:
description: Messaging describing what the user should do next.
type: string
closeConnection:
description: Message that gets sent just before the server closes the connection with the a client. The `message` property gives more information on why the connection was closed.
type: object
properties:
messageType:
description: Specifies that the message is a `"close_connection"` message.
type: string
const: "close_connection"
message:
description: Message describing why the connection was closed.
type: string