diff --git a/contributing.md b/contributing.md index 67b8e2c7e..014a5c914 100644 --- a/contributing.md +++ b/contributing.md @@ -13,9 +13,9 @@ Most files in the project are autogenerated by [openapi-generator](https://opena You need `openapi-generator` to run code generation. There are many ways described in the [readme](https://github.com/OpenAPITools/openapi-generator). In the project we use Docker image `openapitools/openapi-generator-cli` for code generation. -You can just run `sh ./scripts/generate.sh` script and it will do all the work. +You can just run `./scripts/generate.sh` script and it will do all the work. -To download fresh OpenAPI schema run `sh ./scripts/sync.sh` +To download fresh OpenAPI schema run `./scripts/sync.sh` ### Auto-generated test files and FILES manifest The generation script cleans fully managed output (`src`, `docs`, `README.md`, and `composer.json`) before running `openapi-generator`. It intentionally preserves `test`, because PHP test files generated by OpenAPI Generator are scaffolding: they are created when missing, but existing test files are not overwritten on later generation runs. diff --git a/scripts/sync.sh b/scripts/sync.sh index 1240424c3..bad48ecb9 100755 --- a/scripts/sync.sh +++ b/scripts/sync.sh @@ -1,22 +1,25 @@ -#!/bin/bash +#!/usr/bin/env bash source "$(dirname "${BASH_SOURCE[0]}")/common.sh" -defaultBaseUrl="https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi" +defaultBaseUrl="https://fingerprintjs.github.io/openapi" schemaUrl="${1:-$defaultBaseUrl/schemas/fingerprint-server-api-v4.yaml}" examplesBaseUrl="${2:-$defaultBaseUrl/examples}" -mkdir -p ./res - -CURL_OPTS=(-fSL --retry 3) +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="./test/mocks" + +mkdir -p "$(dirname "$schemaDestination")" + require_cmd curl -echo "Downloading \`$schemaUrl\`..." -curl "${CURL_OPTS[@]}" -o ./res/fingerprint-server-api.yaml "$schemaUrl" +echo "Downloading $schemaUrl to $schemaDestination" +curl "${CURL_OPTS[@]}" -o "$schemaDestination" "$schemaUrl" examples=( 'events/get_event_200.json' @@ -40,16 +43,15 @@ examples=( 'errors/500_internal_server_error.json' ) -baseDestination="./test/mocks" - for example in "${examples[@]}"; do - destinationPath="$baseDestination/$example" - destinationDir="$(dirname "$destinationPath")" - mkdir -p "$destinationDir" + destinationPath="$exampleBaseDestination/$example" + mkdir -p "$(dirname "$destinationPath")" exampleUrl="$examplesBaseUrl/$example" - echo "Downloading \`$exampleUrl\` to \`$destinationPath\`..." + echo "Downloading $exampleUrl to $destinationPath" curl "${CURL_OPTS[@]}" -o "$destinationPath" "$exampleUrl" done +echo "All OpenAPI schema downloads complete." + ./scripts/generate.sh