-
Notifications
You must be signed in to change notification settings - Fork 5
/
patch.sh
executable file
·49 lines (38 loc) · 1.84 KB
/
patch.sh
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
#!/usr/bin/env bash
set -o errexit
# this script is to patch [email protected]
# based on https://github.com/APIDevTools/swagger-express-middleware/pull/151
function change_file {
file=$1
line_num=$2
line=$3
kernel=$(uname -s)
if [ ${kernel} = "Darwin" ]; then
sed -i '' -e \
"${line_num}s/.*/${line}/" \
${file}
else
sed -i \
"${line_num}s/.*/${line}/" \
${file}
fi
}
# 1) fix isOpenApi util method
file='./dist/node_modules/swagger-express-middleware-3/lib/helpers/util.js'
change_file $file 147 " return req.openapi !== undefined \&\& req.openapi.operation !== undefined;"
# 2) add basePath to openapi.api
file='./dist/node_modules/swagger-express-middleware-3/lib/middleware/metadata/index.js'
change_file $file 36 " basePath = util.normalizePath(basePath, router); context.api.basePath = basePath;"
# 3) add next() call to validate-request/validate-params middleware
file='./dist/node_modules/swagger-express-middleware-3/lib/middleware/validate-request/validate-params.js'
change_file $file 45 "\/\/ schemaValidator.validate(value);"
change_file $file 52 " } next();"
# 4) add next() call to validate-request/validate-request-body middleware
file='./dist/node_modules/swagger-express-middleware-3/lib/middleware/validate-request/validate-request-body.js'
change_file $file 13 " } next();"
# 5) add next() call to validate-request/validate-content-length middleware
file='./dist/node_modules/swagger-express-middleware-3/lib/middleware/validate-request/validate-content-length.js'
change_file $file 24 " } next();"
# 6) fix request size calculation
file='./dist/node_modules/swagger-express-middleware-3/lib/middleware/validate-request/validate-request-size.js'
change_file $file 15 " let bodyAllowed = req.openapi.operation.requestBody || req.openapi.params.some((param) => {"