mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-27 16:10:30 +08:00
0f607c7a28
- copies that openapi.json file to docs/docs/api/openapi.json as part of start-mock-server.sh. - adds a step to the end of the test-api-contract workflow that just auto-commits changes to the docs/docs/api/openapi.json file. - excludes docs/docs/api/openapi.json from pre-commit since its already been formatted by jq.
45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
|
|
|
# switch to backend directory
|
|
pushd "$parent_path/../../backend"
|
|
|
|
MOCK_SERVER_PORT=8080
|
|
OPENAPI_JSON_FILE_NAME=openapi.json
|
|
|
|
echo "Generating OpenAPI schema..."
|
|
python -m main --print-openapi-schema > $OPENAPI_JSON_FILE_NAME
|
|
echo "Done!"
|
|
|
|
echo "Formatting & Copying OpenAPI schema to docs directory..."
|
|
jq . $OPENAPI_JSON_FILE_NAME > ../docs/docs/api/openapi.json
|
|
|
|
# If oasst-mock-backend docker container is already running,
|
|
# just restart it
|
|
if [ "$(docker ps -q -f name=oasst-mock-backend)" ]; then
|
|
echo "oasst-mock-backend container exists, restarting..."
|
|
docker restart oasst-mock-backend
|
|
else
|
|
echo "Creating new oasst-mock-backend container..."
|
|
docker run --init --rm -d \
|
|
--name oasst-mock-backend \
|
|
-p $MOCK_SERVER_PORT:4010 \
|
|
-v $(pwd):/tmp \
|
|
-P stoplight/prism:4 \
|
|
mock -h 0.0.0.0 "/tmp/$OPENAPI_JSON_FILE_NAME"
|
|
fi
|
|
|
|
echo "Waiting for server to be live..."
|
|
curl --retry-all-errors --retry 5 localhost:$MOCK_SERVER_PORT
|
|
echo ""
|
|
|
|
# if return code is successful, print successful response
|
|
if [ $? -eq 0 ]; then
|
|
echo "Mock server is running at localhost:$MOCK_SERVER_PORT"
|
|
else
|
|
echo "Mock server failed to start"
|
|
fi
|
|
|
|
|
|
popd
|