Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.34
3.0.78
4 changes: 2 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Most files in the project are autogenerated by [swagger-codegen](https://swagger
## Code generation

You need `swagger-codegen` to run code generation. There are many ways described in the [readme](https://github.com/swagger-api/swagger-codegen).
In the project we use local jar file `bin/swagger-codegen-cli.jar`.
In the project we use Docker image `swaggerapi/swagger-codegen-cli-v3` for code generation.

You can just run `sh ./scripts/generate.sh` script and it will do all the work.

Expand Down Expand Up @@ -66,7 +66,7 @@ As an alternative to running the SDK tests locally, you can use Docker:
Project configuration is described in the `config.json` file. To read about available parameters run the command below:

```shell
java -jar ./bin/swagger-codegen-cli.jar config-help -l php
docker run --rm swaggerapi/swagger-codegen-cli-v3:3.0.78 config-help -l php
```

### How to publish
Expand Down
45 changes: 45 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Shared utilities for scripts.
# Source this file: source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

set -euo pipefail

# Change working directory to the project root.
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"

# Verify that required commands are available.
# Usage: require_cmd docker jq
require_cmd() {
for cmd in "$@"; do
if ! command -v "$cmd" &>/dev/null; then
echo "Error: required command '$cmd' is not installed." >&2
exit 1
fi
done
}

# In-place sed that works cross-platform.
# Usage: sed_in_place 'pattern' file [file ...]
sed_in_place() {
if [ "$(uname)" = "Darwin" ]; then
sed -i '' "$@"
else
sed -i "$@"
fi
}

# Like sed_in_place but accepts a glob pattern.
# Usage: sed_in_place_glob 'pattern' ./patternWithGlob/*
sed_in_place_glob() {
local expr="$1"
shift
local files=()
for f in "$@"; do
[ -f "$f" ] && files+=("$f")
done
if [ ${#files[@]} -gt 0 ]; then
sed_in_place "$expr" "${files[@]}"
fi
}
8 changes: 7 additions & 1 deletion scripts/functional.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
docker container run --env-file .env --rm -v $(pwd):/app/ php:8.1-cli php /app/run_checks.php
#!/bin/bash

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

require_cmd docker

docker container run --env-file .env --rm -v "${PWD}:/app/" php:8.1-cli php /app/run_checks.php
132 changes: 63 additions & 69 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
@@ -1,113 +1,107 @@
#!/bin/bash

shopt -s extglob

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

#############
# Constants #
#############
SWAGGER_CODEGEN_IMAGE_VERSION="3.0.78"
PHP_CS_FIXER_IMAGE_VERSION="3.64-php8.3"

######################
# Version Resolution #
######################
require_cmd jq
VERSION=$(jq -r '.version' package.json)

while getopts "v:" arg; do
# shellcheck disable=SC2220
case $arg in
v)
VERSION=$OPTARG
;;
esac
done

# jar was downloaded from here https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.34/

VERSION=${VERSION//develop/dev}

# Convert development version strings into PHP-semver-compatible beta versions.
if [[ $VERSION =~ ^dev[.-]([0-9]+)[.-]([0-9]+)[.-]([0-9]+)[.-]([0-9]+)$ ]]; then
# Example for the regex above:
# dev.1.0.0.0
# dev-1.0.0-0
# dev.1.0.0-0
# dev-1.0.0.0
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}-beta.${BASH_REMATCH[4]}"
# Example for the regex above:
# dev.1.0.0.0
# dev-1.0.0-0
# dev.1.0.0-0
# dev-1.0.0.0
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}-beta.${BASH_REMATCH[4]}"
elif [[ $VERSION =~ ^([0-9]+)[.-]([0-9]+)[.-]([0-9]+)[.-]dev[.-]([0-9]+)$ ]]; then
# Example for the regex above:
# 1.0.0.dev.0
# 1.0.0.dev-0
# 1.0.0-dev-0
# 1.0.0-dev.0
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}-beta.${BASH_REMATCH[4]}"
# Example for the regex above:
# 1.0.0.dev.0
# 1.0.0.dev-0
# 1.0.0-dev-0
# 1.0.0-dev.0
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}-beta.${BASH_REMATCH[4]}"
elif [[ $VERSION == dev-* ]]; then
_temp_part=${VERSION#dev-}
VERSION="${_temp_part//-/.}-beta"
_temp_part=${VERSION#dev-}
VERSION="${_temp_part//-/.}-beta"
elif [[ $VERSION == *-dev* ]]; then
_temp_part=${VERSION#*-dev}
_temp_part=${_temp_part//-/.}
VERSION="${VERSION%%-dev*}-beta$_temp_part"
_temp_part=${VERSION#*-dev}
_temp_part=${_temp_part//-/.}
VERSION="${VERSION%%-dev*}-beta$_temp_part"
fi

echo "VERSION: $VERSION"

# Platform check
platform=$(uname)
(
# Model file fix
if [ "$platform" = "Darwin" ]; then
sed -i '' "s/\"artifactVersion\": \".*\"/\"artifactVersion\": \"$VERSION\"/g" config.json
else
sed -i "s/\"artifactVersion\": \".*\"/\"artifactVersion\": \"$VERSION\"/g" config.json
fi
)
# Update `config.json` version
sed_in_place "s/\"artifactVersion\": \".*\"/\"artifactVersion\": \"$VERSION\"/g" config.json

################
# Generate SDK #
################
require_cmd docker

# clean models before generating
rm -f ./src/Model/*

java -jar ./bin/swagger-codegen-cli.jar generate -t ./template -l php -i ./res/fingerprint-server-api.yaml -o ./ -c config.json --type-mapping RawDeviceAttributes=array,WebhookRawDeviceAttributes=array,Tag=array,GeolocationSubdivisions=array
docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/local" -w /local \
"swaggerapi/swagger-codegen-cli-v3:${SWAGGER_CODEGEN_IMAGE_VERSION}" generate \
-t ./template \
-l php \
-i ./res/fingerprint-server-api.yaml \
-o ./ \
-c ./config.json \
--type-mapping RawDeviceAttributes=array,WebhookRawDeviceAttributes=array,Tag=array,GeolocationSubdivisions=array

# Format generated code
if [ ! -f .php-cs-fixer.php ]; then
echo ".php-cs-fixer.php configuration file not found!"
exit 1
fi

echo "Using .php-cs-fixer.php configuration:"
cat .php-cs-fixer.php

docker run --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:3.64-php8.3 fix --config=/code/.php-cs-fixer.php

# fix invalid code generated for Models and docs
(
# Model and docs files fix
if [ "$platform" = "Darwin" ]; then
sed -i '' 's/\\Fingerprint\\ServerAPI\\Model\\array/array/' ./src/Model/*
sed -i '' 's/\\Fingerprint\\ServerAPI\\Model\\mixed/mixed/' ./src/Model/*
sed -i '' 's/?mixed/mixed/' ./src/Model/*
sed -i '' 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\array\*\*\](array\.md)/array/' ./src/docs/Model/*
sed -i '' 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\mixed\*\*\](mixed\.md)/mixed/' ./src/docs/Model/*

else
sed -i 's/\\Fingerprint\\ServerAPI\\Model\\array/array/' ./src/Model/*
sed -i 's/\\Fingerprint\\ServerAPI\\Model\\mixed/mixed/' ./src/Model/*
sed -i 's/?mixed/mixed/' ./src/Model/*
sed -i 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\array\*\*\](array\.md)/array/' ./src/docs/Model/*
sed -i 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\mixed\*\*\](mixed\.md)/mixed/' ./src/docs/Model/*
fi
)
docker run --rm -u "$(id -u):$(id -g)" -v "${PWD}:/code" \
"ghcr.io/php-cs-fixer/php-cs-fixer:${PHP_CS_FIXER_IMAGE_VERSION}" fix \
--config=/code/.php-cs-fixer.php

# Fix generated code
sed_in_place_glob 's/\\Fingerprint\\ServerAPI\\Model\\array/array/' ./src/Model/*
sed_in_place_glob 's/\\Fingerprint\\ServerAPI\\Model\\mixed/mixed/' ./src/Model/*
sed_in_place_glob 's/?mixed/mixed/' ./src/Model/*
sed_in_place_glob 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\array\*\*\](array\.md)/array/' ./src/docs/Model/*
sed_in_place_glob 's/\[\*\*\\Fingerprint\\ServerAPI\\Model\\mixed\*\*\](mixed\.md)/mixed/' ./src/docs/Model/*

# cleanup replaced models from readme
(
patterns=(
# Cleanup documentation
patterns=(
'\[RawDeviceAttribute\](docs\/Model\/RawDeviceAttribute\.md)'
'\[RawDeviceAttributeError\](docs\/Model\/RawDeviceAttributeError\.md)'
'\[RawDeviceAttributes\](docs\/Model\/RawDeviceAttributes\.md)'
'\[WebhookRawDeviceAttributes\](docs\/Model\/WebhookRawDeviceAttributes\.md)'
'\[Tag\](docs\/Model\/Tag\.md)'
'\[GeolocationSubdivisions\](docs\/Model\/GeolocationSubdivisions\.md)'
'\[GeolocationSubdivision\](docs\/Model\/GeolocationSubdivision\.md)'
)
if [ "$platform" = "Darwin" ]; then
for pattern in "${patterns[@]}"; do
sed -i '' "/$pattern/d" src/README.md
done
else
for pattern in "${patterns[@]}"; do
sed -i "/$pattern/d" src/README.md
done
fi
)
for pattern in "${patterns[@]}"; do
sed_in_place "/$pattern/d" src/README.md
done

# Move generated files
mv -f src/README.md ./README.md
mv -f src/composer.json composer.json
rm ./docs/Api/*
Expand Down
8 changes: 7 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
docker-compose run composer install --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
#!/bin/bash

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

require_cmd docker-compose

docker-compose run composer install --profile --ignore-platform-reqs --no-interaction --no-ansi --no-scripts --no-suggest --prefer-dist
41 changes: 33 additions & 8 deletions scripts/sync.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
#!/bin/bash

curl -o ./res/fingerprint-server-api.yaml https://fingerprintjs.github.io/fingerprint-pro-server-api-openapi/schemas/fingerprint-server-api-compact.yaml
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

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_OPTS=(-fSL --retry 3)
if [[ "${TRACE:-}" != "true" && "${ACTIONS_STEP_DEBUG:-}" != "true" ]]; then
CURL_OPTS+=(-s)
fi

require_cmd curl

echo "Downloading \`$schemaUrl\`..."
curl "${CURL_OPTS[@]}" -o ./res/fingerprint-server-api.yaml "$schemaUrl"

examplesList=(
'get_visits_200_limit_1.json'
Expand Down Expand Up @@ -34,14 +50,23 @@ 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
examplesBaseDestination="./test/mocks"
mkdir -p "$examplesBaseDestination"

download_example() {
local subPath="$1"
shift
local examples=("$@")

for example in "${examples[@]}"; do
echo "Downloading \`$examplesBaseUrl/$example\` to \`$examplesBaseDestination/$example\`..."
curl "${CURL_OPTS[@]}" -o "$examplesBaseDestination/$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[@]}"

sed -i '' '/IpInfoResult:/,/IpBlockListResult:/ { /dataCenter:/ { N; d; }; }' ./res/fingerprint-server-api.yaml
sed_in_place '/IpInfoResult:/,/IpBlockListResult:/ { /dataCenter:/ { N; d; }; }' ./res/fingerprint-server-api.yaml

./scripts/generate.sh
8 changes: 7 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
docker-compose run phpunit
#!/bin/bash

source "$(dirname "${BASH_SOURCE[0]}")/common.sh"

require_cmd docker-compose

docker-compose run phpunit
2 changes: 1 addition & 1 deletion src/Api/FingerprintApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Botd.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/Model/BotdBot.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/Model/BotdBotResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
2 changes: 1 addition & 1 deletion src/Model/BrowserDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* OpenAPI spec version: 3
* Contact: support@fingerprint.com
* Generated by: https://github.com/swagger-api/swagger-codegen.git
* Swagger Codegen version: 3.0.34
* Swagger Codegen version: 3.0.78
*/
/**
* NOTE: This class is auto generated by the swagger code generator program.
Expand Down
Loading
Loading