diff --git a/contributing.md b/contributing.md index 638a482..fea23ca 100644 --- a/contributing.md +++ b/contributing.md @@ -26,7 +26,7 @@ Use the Gradle build to invoke `openapi-generator` and generate the code and doc ./gradlew build ``` -To download the latest OpenAPI schema from [fingerprintjs/fingerprint-pro-server-api-openapi](https://github.com/fingerprintjs/fingerprint-pro-server-api-openapi), run `./scripts/sync.sh` +To download the latest OpenAPI schema from [fingerprintjs/openapi](https://github.com/fingerprintjs/openapi), run `./scripts/sync.sh` ### Updating the codegen engine and templates diff --git a/scripts/sync.sh b/scripts/sync.sh index ec9d795..02e92b6 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -1,10 +1,28 @@ #!/usr/bin/env bash +set -euo pipefail -set -ex +# Resolve paths relative to the repository root, so the script can be run from +# any working directory. +cd "$(dirname "${BASH_SOURCE[0]}")/.." -curl -fsSL -o ./res/fingerprint-server-api.yaml https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/schemas/fingerprint-server-api-v4.yaml +defaultBaseUrl="https://fingerprintjs.github.io/openapi" +schemaUrl="${1:-$defaultBaseUrl/schemas/fingerprint-server-api-v4.yaml}" +examplesBaseUrl="${2:-$defaultBaseUrl/examples}" -examplesList=( +CURL_OPTS=(-fSL --retry 3 --proto-redir '=https' --connect-timeout 10 --max-time 300) +if [[ "${TRACE:-}" != "true" && "${ACTIONS_STEP_DEBUG:-}" != "true" ]]; then + CURL_OPTS+=(-s) +fi + +schemaDestination="./res/fingerprint-server-api.yaml" +exampleBaseDestination="./sdk/src/test/resources/mocks" + +mkdir -p "$(dirname "$schemaDestination")" + +echo "Downloading $schemaUrl to $schemaDestination" +curl "${CURL_OPTS[@]}" -o "$schemaDestination" "$schemaUrl" + +examples=( 'webhook/webhook_event.json' 'events/get_event_200.json' 'events/get_event_ruleset_200.json' @@ -36,6 +54,13 @@ examplesList=( 'errors/500_internal_server_error.json' ) -for example in "${examplesList[@]}"; do - curl --create-dirs -fsSL -o ./sdk/src/test/resources/mocks/"$example" https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/examples/"$example" -done \ No newline at end of file +for example in "${examples[@]}"; do + destinationPath="$exampleBaseDestination/$example" + mkdir -p "$(dirname "$destinationPath")" + + exampleUrl="$examplesBaseUrl/$example" + echo "Downloading $exampleUrl to $destinationPath" + curl "${CURL_OPTS[@]}" -o "$destinationPath" "$exampleUrl" +done + +echo "All OpenAPI schema downloads complete."