forked from Azure/azure-functions-openapi-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-openapi-document.sh
executable file
·121 lines (97 loc) · 2.86 KB
/
get-openapi-document.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
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
#!/bin/bash
set -e
function usage() {
cat <<USAGE
Usage: $0 <options>
Options:
[-p|--functionapp-path] Function app path, relative to the repository root. It can be the project directory or compiled app directory.
Default: '.'
[-u|--base-uri] Base URI of the function app.
Default: 'http://localhost:7071/api/'
[-e|--endpoint] OpenAPI document endpoint.
Default: 'swagger.json'
[-o|--output-path] Output directory to store the generated OpenAPI document, relative to the repository root.
Default: 'generated'
[-f|--output-filename] Output filename for the generated OpenAPI document.
Default: 'swagger.json'
[-d|--delay] Delay in second between the function app run and document generation.
Default: 30
[-c|--use-codespaces] Switch indicating whether to use GitHub Codespaces or not.
[-h|--help] Show this message.
USAGE
exit 1
}
functionapp_path="."
base_uri="http://localhost:7071/api/"
endpoint="swagger.json"
output_path="generated"
output_filename="swagger.json"
delay=30
repository_root=$GITHUB_WORKSPACE
if [[ $# -eq 0 ]]; then
functionapp_path="."
base_uri="http://localhost:7071/api/"
endpoint="swagger.json"
output_path="generated"
output_filename="swagger.json"
delay=30
repository_root=$GITHUB_WORKSPACE
fi
while [[ "$1" != "" ]]; do
case $1 in
-p | --functionapp-path)
shift
functionapp_path=$1
;;
-u | --base-uri)
shift
base_uri=$1
;;
-e | --endpoint)
shift
endpoint=$1
;;
-o | --output-path)
shift
output_path=$1
;;
-f | --output-filename)
shift
output_filename=$1
;;
-d | --delay)
shift
delay=$1
;;
-c | --use_codespaces)
repository_root=$CODESPACE_VSCODE_FOLDER
;;
-h | --help)
usage
exit 1
;;
*)
usage
exit 1
;;
esac
shift
done
current_directory=$(pwd)
cd "$repository_root/$functionapp_path"
# Run the function app in the background
func start --verbose false &
sleep $delay
request_uri="$(echo "$base_uri" | sed 's:/*$::')/$(echo "$endpoint" | sed 's:^/*::')"
filepath="$repository_root/$(echo "$output_path" | sed 's:/*$::')/$(echo "$output_filename" | sed 's:^/*::')"
if [ ! -d "$repository_root/$output_path" ]; then
mkdir "$repository_root/$output_path"
fi
# Download the OpenAPI document
curl $request_uri > $filepath
# Stop the function app
PID=$(lsof -nP -i4TCP:7071 | grep LISTEN | awk '{print $2}')
if [[ "" != "$PID" ]]; then
kill -9 $PID
fi
cd $current_directory