openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
scripts/mock
52lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | cd "$(dirname "$0")/.." |
| 6 | |
| 7 | if [[ -n "$1" && "$1" != '--'* ]]; then |
| 8 | URL="$1" |
| 9 | shift |
| 10 | else |
| 11 | URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)" |
| 12 | fi |
| 13 | |
| 14 | # Check if the URL is empty |
| 15 | if [ -z "$URL" ]; then |
| 16 | echo "Error: No OpenAPI spec path/url provided or found in .stats.yml" |
| 17 | exit 1 |
| 18 | fi |
| 19 | |
| 20 | echo "==> Starting mock server with URL ${URL}" |
| 21 | |
| 22 | # Run steady mock on the given spec |
| 23 | if [ "$1" == "--daemon" ]; then |
| 24 | # Pre-install the package so the download doesn't eat into the startup timeout |
| 25 | npm exec --package=@stdy/cli@0.22.1 -- steady --version |
| 26 | |
| 27 | npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & |
| 28 | |
| 29 | # Wait for server to come online via health endpoint (max 30s) |
| 30 | echo -n "Waiting for server" |
| 31 | attempts=0 |
| 32 | while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do |
| 33 | if ! kill -0 $! 2>/dev/null; then |
| 34 | echo |
| 35 | cat .stdy.log |
| 36 | exit 1 |
| 37 | fi |
| 38 | attempts=$((attempts + 1)) |
| 39 | if [ "$attempts" -ge 300 ]; then |
| 40 | echo |
| 41 | echo "Timed out waiting for Steady server to start" |
| 42 | cat .stdy.log |
| 43 | exit 1 |
| 44 | fi |
| 45 | echo -n "." |
| 46 | sleep 0.1 |
| 47 | done |
| 48 | |
| 49 | echo |
| 50 | else |
| 51 | npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" |
| 52 | fi |