openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
scripts/mock
52lines · modeblame
d2738d42Stainless Bot2 years ago | 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 | | |
85ac9313stainless-app[bot]3 months ago | 22 | # Run steady mock on the given spec |
d2738d42Stainless Bot2 years ago | 23 | if [ "$1" == "--daemon" ]; then |
9b1bb6eestainless-app[bot]3 months ago | 24 | # Pre-install the package so the download doesn't eat into the startup timeout |
de2c7b1dstainless-app[bot]2 months ago | 25 | npm exec --package=@stdy/cli@0.20.2 -- steady --version |
9b1bb6eestainless-app[bot]3 months ago | 26 | |
de2c7b1dstainless-app[bot]2 months ago | 27 | npm exec --package=@stdy/cli@0.20.2 -- 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 & |
d2738d42Stainless Bot2 years ago | 28 | |
85ac9313stainless-app[bot]3 months ago | 29 | # Wait for server to come online via health endpoint (max 30s) |
d2738d42Stainless Bot2 years ago | 30 | echo -n "Waiting for server" |
9b1bb6eestainless-app[bot]3 months ago | 31 | attempts=0 |
85ac9313stainless-app[bot]3 months ago | 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 | |
9b1bb6eestainless-app[bot]3 months ago | 38 | attempts=$((attempts + 1)) |
| 39 | if [ "$attempts" -ge 300 ]; then | |
| 40 | echo | |
85ac9313stainless-app[bot]3 months ago | 41 | echo "Timed out waiting for Steady server to start" |
| 42 | cat .stdy.log | |
9b1bb6eestainless-app[bot]3 months ago | 43 | exit 1 |
| 44 | fi | |
d2738d42Stainless Bot2 years ago | 45 | echo -n "." |
| 46 | sleep 0.1 | |
| 47 | done | |
| 48 | | |
| 49 | echo | |
| 50 | else | |
de2c7b1dstainless-app[bot]2 months ago | 51 | npm exec --package=@stdy/cli@0.20.2 -- 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" |
d2738d42Stainless Bot2 years ago | 52 | fi |