-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi3.yaml
512 lines (512 loc) · 15.5 KB
/
openapi3.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
openapi: 3.0.0
info:
title: CRM API v1.0.0
description: "<!--\nauthorLink: 'https://github.com/novakzaballa'\nauthorName: 'Novak Zaballa'\nDate: 'Apr 16 2020'\n-->\n\n# CRM REST API code example\n\n## Author: Novak Zaballa\n\nThe scope of this sample code project is users and customers management of a CRM.\n\nThis project has been built with Serverless Framework and targeting AWS lambda with Node.js + DynamoDB. You can deploy the proyect to AWS installing and configuring serverless, or you can run the services locally, using the [serverless-offline](https://github.com/dherault/serverless-offline) plugin, which is included. The offline configuration also includes a local DynamoDB instance is provided by the [serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local) plugin.\n\n## Setup and test locally\n\nTo test your service locally, without having to deploy it first, you will need node.js (tested with v13.7.0) and follow the steps below in the root directory of the project.\n\n```bash\nnpm install\nserverless dynamodb install\nserverless dynamodb start --migrate\n```\n\nThe --migrate option creates the schema. Ctl+C to stop the local DynamoDB. The DB schema and data will be lost since by default the local DB is stored in memory.\n\n## Run service offline\n\nTo test the project locally use:\n\n```bash\nserverless offline start\n```\n\nAlternatively you can debug the project with VS Code. This repository includes the launch.json file needed by VS Code to run and debug this serverless project locally. How ever dynamodb needs to be started.\n\n## Configure and Deploy service to AWS\n\nFor production you will need to configure authetication the OAuth 2 provider. Replace the file oauth2_public_key.pem in the root directory with the right public signature PEM file. Also cnfigure the file secrets.json with the corresponding OAUTH_AUDIENCE value.\n\nTo deploy the service you need an account in AWS. Use the following command:\n\n```bash\nserverless deploy -v\n``` \n\n### Authorization for testing\n\nEvery request must include an authorization header containing the OAuth Bearer token. For testing purposes currently an Auth0 account is in use, The request content type must be application/json as per the examples below. While in dev stage, I will provide valid access token of quarklap user (with only customer priveleges and not users admin permissions) via slack channel.\n\n### Live Demo\n\nYou can test locally following the former instructions, however it is also a live test in my aws account. Change the Servers to https://mspjeecyw1.execute-api.us-east-1.amazonaws.com/dev/api in order to use it, and get a valid toket for user with email = [email protected] and password= Myt3stPass#, to start testing. Admin credentials will be provided via email or slack.\n\n"
contact: {}
version: '1.0'
servers:
- url: https://mspjeecyw1.execute-api.us-east-1.amazonaws.com/dev/api
variables: {}
- url: http://localhost:3000/dev/api
variables: {}
paths:
/authorize:
post:
tags:
- Authenticate User
summary: Authenticate user
description: If email and password are correct, returns an access token to be used in future calls to API.
operationId: Authorizeexample
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/AuthorizeexampleRequest'
example:
email: [email protected]
password: Myt3stPass#
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
security: []
/users/role:
post:
tags:
- Users Management
summary: setUserRole
description: Set the role of an user in IDP (Auth0)
operationId: setUserRole
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/setUserRoleRequest'
example:
email: [email protected]
role: user
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
/users:
post:
tags:
- Users Management
summary: createUser
description: Create a user in the IDP (Auth0)
operationId: createUser
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/createUserRequest'
example:
email: [email protected]
password: Myt3stPass#
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
get:
tags:
- Users Management
summary: listUsers
description: List users from IDP (Auth0)
operationId: listUsers
parameters:
- name: per_page
in: query
description: 'Number of users returned per page'
required: true
style: form
explode: true
schema:
type: integer
example: 50
- name: page
in: query
description: '0 to get first page.'
required: true
style: form
explode: true
schema:
type: integer
example: '0'
responses:
200:
description: ''
headers: {}
deprecated: false
/users/{userId}:
delete:
tags:
- Users Management
summary: deleteUser
description: Delete user from Auth0 IDP
operationId: deleteUser
parameters:
- name: userId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the user to delete
responses:
200:
description: ''
headers: {}
deprecated: false
put:
tags:
- Users Management
summary: updateUser
description: 'Update data of an IDP user '
operationId: updateUser
parameters:
- name: userId
in: path
description: 'ID of the user to be updated'
required: true
style: simple
schema:
type: string
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/updateUserRequest'
example:
given_name: Jhon E.
family_name: Doe Oe
password: MyT3stPass#
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
/customers:
post:
tags:
- Customers API
summary: createCustomer
description: Creates a customer in the CRM database
operationId: createCustomer
parameters: []
requestBody:
description: 'Add new customer to the CRM'
content:
application/json:
schema:
$ref: '#/components/schemas/putCustomerRequest'
example:
Name: Pedro Pablo
Surname: Marmol
Phone: (234)534543 654
Email: [email protected]
Age: 43
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
get:
tags:
- Customers API
summary: listCustomers
description: List Customers from Database.
operationId: listCustomers
parameters:
- name: pageSize
in: query
description: 'Number of customers to be returned in every call to this endpoint.'
required: true
style: form
explode: true
schema:
type: integer
format: int32
example: 3
- name: startKey
in: query
description: 'Optional, Empty or lastkey field returned by a previous call to this endpoint'
required: false
style: form
explode: true
schema:
type: string
responses:
200:
description: ''
headers: {}
deprecated: false
/customers/{customerId}:
get:
tags:
- Customers API
summary: getCustomer
description: Get one Customer from DynamoDB table.
operationId: getCustomer
parameters:
- name: customerId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the customer to get data from
example: "243432324"
responses:
200:
description: ''
headers: {}
deprecated: false
delete:
tags:
- Customers API
summary: deleteCustomer
description: Deletes a determined customer by its ID
operationId: deleteCustomer
parameters:
- name: customerId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the customer to get data from
responses:
200:
description: ''
headers: {}
deprecated: false
put:
tags:
- Customers API
summary: updateCustomer
description: Update an existing customer in DynamoDB
operationId: updateCustomer
parameters:
- name: customerId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the customer to be updated.
example: "243432324"
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/updateCustomerRequest'
example:
Name: Jorge Raul
Surname: Thousand
Age: 52
Email: [email protected]
Phone: (122)23878 343
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
/customers/{customerId}/photo:
put:
tags:
- Customers API
summary: addCustomerPhoto
description: Add a photo in S3 to an existing Customer
operationId: addCustomerPhoto
parameters:
- name: customerId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the customer to be updated with a new photo.
example: "243432324"
requestBody:
description: 'Base64 encoded JPG, PNG or GIF Image . Max size configured in settings.json. (150KB default)'
content:
text/plain:
schema:
type: string
example: /9jr/4AAQSkZJRgABAgAAAQABAAD/7QCcUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAI.....
required: true
responses:
200:
description: ''
headers: {}
deprecated: false
get:
tags:
- Customers API
summary: getCustomerPhoto
description: Get the customer photo in S3.
operationId: getCustomerPhoto
parameters:
- name: Accept
in: header
description: ''
required: true
style: simple
schema:
type: string
example: image/jpeg
- name: customerId
in: path
style: simple
schema:
type: string
required: true
description: Alphanumeric ID of the customer to be updated with a new photo.
example: "243432324"
responses:
200:
description: 'Image returned'
content:
image/jpeg:
schema:
type: string
format: binary
headers: {}
deprecated: false
components:
schemas:
setUserRoleRequest:
title: setUserRoleRequest
required:
- email
- role
type: object
properties:
email:
type: string
format: email
role:
type: string
format: anyof ["user","admin"]
example:
email: [email protected]
role: user
createUserRequest:
title: createUserRequest
required:
- given_name
- family_name
- email
- password
type: object
properties:
given_name:
type: string
family_name:
type: string
email:
type: string
format: email
password:
type: string
format: password
example:
given_name: Jhon
family_name: Doe
email: [email protected]
password: Myt3stPass#
updateUserRequest:
title: updateUserRequest
description: Requieres any of the following
type: object
properties:
given_name:
type: string
family_name:
type: string
email:
type: string
format: email
password:
type: string
format: password
blocked:
type: boolean
example:
given_name: Jhon E.
family_name: Doe Oe
password: MyT3stPass#
AuthorizeexampleRequest:
title: AuthorizeexampleRequest
required:
- email
- password
type: object
properties:
email:
type: string
format: email
password:
type: string
format: password
example:
email: [email protected]
password: Myt3stPass#
putCustomerRequest:
title: putCustomerRequest
required:
- Name
- Surname
- Phone
- Email
- Age
type: object
properties:
Name:
type: string
minLength: 2
maxLength: 255
Surname:
type: string
minLength: 2
maxLength: 255
Phone:
type: string
format: phonenumber
Email:
type: string
format: email
Age:
type: integer
minimum: 16
maximum: 110
example:
Name: Pedro Pablo
Surname: Marmol
Phone: (234)534543 654
Email: [email protected]
Age: 43
updateCustomerRequest:
title: updateCustomerRequest
required:
- Name
- Surname
- Age
- Email
- Phone
type: object
properties:
Name:
type: string
minLength: 2
maxLength: 255
Surname:
type: string
minLength: 2
maxLength: 255
Phone:
type: string
format: phonenumber
Email:
type: string
format: email
Age:
type: integer
format: int32
minimum: 16
maximum: 110
example:
Name: Jorge Raul
Surname: Thousand
Age: 52
Email: [email protected]
Phone: (122)23878 343
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
security:
- bearerAuth: []
tags:
- name: Authenticate User
- name: Customers API
- name: Users Management