-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmiddy_validator.middy.txt
29 lines (22 loc) · 1.59 KB
/
middy_validator.middy.txt
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
┏━━━━━━━━━━━━━━━━━━━━━┓
┃ MIDDY_VALIDATOR ┃
┗━━━━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> #See API request response validation doc
@middy/validator #Version: part of Middy (see its doc)
VALIDATOR([OPTS])->MIDDY_MDWR #Validates REQ|RES
OPTS.eventSchema #FUNC(REQ)->[>]BOOL (def: none)
#If returns false, throws MIDDY_ERROR 400
#Done in 'before' STEP
OPTS.contextSchema #FUNC(NCONTEXT)->[>]BOOL (def: none)
#If returns false, throws MIDDY_ERROR 500
#Done in 'before' STEP
OPTS.responseSchema #FUNC(RES)->[>]BOOL (def: none)
#If returns false, throws MIDDY_ERROR 500
#Done in 'after' STEP
ERROR.cause.data #FUNC.errors from OPTS.*Schema FUNC
#I.e. if FUNC() returns false, should set FUNC.errors OBJ_ARR
OPTS.languages.LANG #FUNC(OBJ_ARR) called on ERROR.cause.data
#Meant to mutate OBJ_ARR based on language
#Def: none
OPTS.defaultLanguage #'LANG' used by OPTS.languages.*
#Def: NCONTEXT.preferredLanguage (from @middy/http-content-negotiation), or 'en'