-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.spec.yaml
184 lines (180 loc) · 6.07 KB
/
api.spec.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
openapi: 3.1.0
x-stoplight:
id: juus8uwnzzal5
info:
description: "This API manages the flow of a tap beer dispenser mechanism to help those bars that allow their clients
to serve themselves beer. Every time a client opens the tap, this API starts counting how many liters come out of the
tap until is closed. \n\nAfter that, the bartender could know how much their customers have spent drinking beer! 🍻"
version: 1.0.0
title: Beer tap dispenser
contact:
name: Rviewer dev team
url: 'https://rviewer.io'
email: [email protected]
license:
name: MIT
url: 'https://choosealicense.com/licenses/mit/'
paths:
/dispenser:
post:
summary: Create a new dispenser
description: |
This endpoint will create a new dispenser with a configuration about how much volume comes out (litres per second)
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
flow_volume:
description: Flow volume is the number of liters per second are coming out from the tap
type: number
required:
- flow_volume
example:
flow_volume: 0.0653
responses:
'200':
description: Dispenser created correctly
content:
application/json:
schema:
type: object
properties:
id:
description: Id of the created dispenser
type: string
format: uuid
flow_volume:
description: The configured flow volume (litres/second) for the new dispenser
type: number
required:
- id
- flow_volume
example:
id: e678cd48-76cc-474c-b611-94dd2df533cb
flow_volume: 0.0653
'500':
description: Unexpected API error
'/dispenser/{id}/status':
put:
summary: Change the dispenser status for a given dispenser Id
description: |
This endpoint will change the status for a given dispenser.
The status could be:
> `open`: The dispenser will start counting how much time (and beer) is spent on this usage
> `close`: The dispenser closes immediately the beer flow and stops counting
parameters:
- in: path
name: id
description: Dispenser Id
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
status:
description: Status of the flow dispenser
type: string
enum:
- open
- close
updated_at:
description: Timestamp for the update
type: string
format: date-time
required:
- status
example:
status: open
updated_at: '2022-01-01T02:00:00Z'
responses:
'202':
description: Status of the tap changed correctly
'409':
description: Dispenser is already opened/closed
'500':
description: Unexpected API error
'/dispenser/{id}/spending':
get:
summary: Returns the money spent by the given dispenser Id
description: |
Whether the dispenser is open or close, this endpoint returns how much money has this dispenser ID spent break
down by its uses. This endpoint could be request at any time, even if the tap is open
(so, the `closed_at` field would be `null`).
To do so, we will use a reference value of 12.25€/l.
So, if the dispenser has configured the flow volume ratio as 0.064 litres/second and the tap was open for
22 seconds, the total spent for this usage is 17.248.
parameters:
- in: path
name: id
description: Dispenser Id
required: true
schema:
type: string
responses:
'200':
description: Total amount spent by the dispenser
content:
application/json:
schema:
type: object
properties:
amount:
description: Total amount
type: number
usages:
description: Usage lines
type: array
items:
$ref: '#/components/schemas/DispenserSpendingLine'
required:
- amount
- usages
example:
amount: 57.678
usages:
- opened_at: '2022-01-01T02:00:00Z'
closed_at: '2022-01-01T02:00:50Z'
flow_volume: 0.064
total_spent: 39.2
- opened_at: '2022-01-01T02:50:58Z'
closed_at: '2022-01-01T02:51:20Z'
flow_volume: 0.064
total_spent: 17.248
- opened_at: '2022-01-01T13:50:58Z'
closed_at: null
flow_volume: 0.064
total_spent: 1.23
'404':
description: Requested dispenser does not exist
'500':
description: Unexpected API error
components:
schemas:
DispenserSpendingLine:
type: object
properties:
opened_at:
type: string
format: date-time
example: '2022-01-01T02:00:00Z'
closed_at:
type:
string
nullable: true
format: date-time
example: '2022-01-01T02:00:50Z'
flow_volume:
type: number
example: 0.064
total_spent:
type: number
example: 39.2
x-internal: false