-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathmock
More file actions
executable file
·51 lines (40 loc) · 1.65 KB
/
mock
File metadata and controls
executable file
·51 lines (40 loc) · 1.65 KB
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
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
if [[ -n "$1" && "$1" != '--'* ]]; then
URL="$1"
shift
else
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
fi
# Check if the URL is empty
if [ -z "$URL" ]; then
echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
exit 1
fi
# download spec into a temp file and then modify it
SPEC_PATH="$(mktemp)"
echo "==> Downloading spec from ${URL} to ${SPEC_PATH}"
curl -s "$URL" -o "$SPEC_PATH"
echo "==> Modifying SSE schemas for the mock server"
yq -i '(.. | select(has("text/event-stream")).["text/event-stream"].schema) = {"type": "string"}' "$SPEC_PATH"
echo "==> Starting mock server with file ${SPEC_PATH}"
# Run steady mock on the given spec
if [ "$1" == "--daemon" ]; then
# Pre-install the package so the download doesn't eat into the startup timeout
npm exec --package=@stdy/cli@0.20.2 -- steady --version
npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
# Wait for server to come online via health endpoint (max 30s)
echo -n "Waiting for server"
while ! grep -q "Error: \|Server started on port 4010" ".stdy.log"; do
echo -n "."
sleep 0.1
done
if grep -q "Error: " ".stdy.log"; then
cat .stdy.log
exit 1
fi
echo
else
npm exec --package=@stdy/cli@0.20.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
fi