From c97726d8b854a8322f5b64885119f53f34600548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20Ayd=C4=B1n?= Date: Tue, 3 Feb 2026 21:42:10 +0300 Subject: [PATCH] chore: improve sync.sh script Add strict error handling, retry logic, and reduce code duplication. Related-Task: INTER-1793 --- sync.sh | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/sync.sh b/sync.sh index 5125b396..f2ef8ba4 100755 --- a/sync.sh +++ b/sync.sh @@ -1,6 +1,13 @@ #!/bin/bash +set -euo pipefail -curl -o ./res/fingerprint-server-api.yaml https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/schemas/fingerprint-server-api-compact.yaml +defaultBaseUrl="https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi" +schemaUrl="${1:-$defaultBaseUrl/schemas/fingerprint-server-api-compact.yaml}" +examplesBaseUrl="${2:-$defaultBaseUrl/examples}" + +mkdir -p ./res + +curl -fSL --retry 3 -o ./res/fingerprint-server-api.yaml "$schemaUrl" examplesList=( 'get_visits_200_limit_1.json' @@ -34,12 +41,21 @@ sharedExamplesList=( '429_error_too_many_requests.json' ) -for example in ${examplesList[*]}; do - curl -o ./test/mocks/"$example" https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/examples/"$example" -done +baseDestination="./test/mocks" +mkdir -p "$baseDestination" + +download_example() { + local subpath="$1" + shift + local examples=("$@") + + for example in "${examples[@]}"; do + echo "Downloading $example" + curl -fSL --retry 3 -o "$baseDestination/$example" "$examplesBaseUrl/$subpath$example" + done +} -for example in ${sharedExamplesList[*]}; do - curl -o ./test/mocks/"$example" https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/examples/shared/"$example" -done +download_example "" "${examplesList[@]}" +download_example "shared/" "${sharedExamplesList[@]}" ./generate.sh