- Go > 1.18
- OpenAPI generator: https://openapi-generator.tech/docs/installation#bash-launcher-script
The specific version used can be found in client/.openapi-generator/VERSION
Install it globally (required by generate.sh):
npm install -g @openapitools/openapi-generator-cli- openapi format: https://github.com/thim81/openapi-format
Install it globally (required by generate.sh):
npm install -g openapi-format./generate.sh automatically picks the OpenAPI source:
- It first tries
http://localhost:4242/docs/openapi.json - If local Unleash is not reachable, it falls back to
https://us.app.unleash-hosted.com/ushosted/docs/openapi.json
This lets you generate the client against a specific local server version (for example a pinned enterprise image).
During generation, servers is normalized to a deterministic placeholder (https://unleash.example.com) to avoid source-specific URL diffs in generated docs (local vs hosted).
You can override this placeholder if needed:
OPENAPI_SERVER_URL=https://my-unleash.example ./generate.shThe docker-compose.yml defaults to OSS Unleash:
docker compose upTo start the enterprise image, set UNLEASH_DOCKER_IMAGE (same pattern used in terraform-provider-unleash):
UNLEASH_DOCKER_IMAGE=unleashorg/unleash-enterprise:latest docker compose upTo pin a specific enterprise version (for example 7.4.1):
UNLEASH_DOCKER_IMAGE=unleashorg/unleash-enterprise:7.4.1 docker compose upWith that running, ./generate.sh will use http://localhost:4242/docs/openapi.json from that exact image.
Enterprise features also require a valid license key, passed as UNLEASH_DEV_LICENSE:
UNLEASH_DEV_LICENSE=<your license key> \
UNLEASH_DOCKER_IMAGE=unleashorg/unleash-enterprise:latest \
docker compose up./generate.shAfter generating the code you can use main.go to test it works (before running the command below start Unleash server with docker compose up)
go run main.go -unleash-api http://localhost:4242 -authorization *:*.unleash-insecure-admin-api-tokenTesting relies on a running environment. You can use docker-compose.yml file to spin up an environment with a clean state and predictable admin API token.
Note: some tests rely on an enterprise version of Unleash. To run those tests locally you need to set UNLEASH_ENTERPRISE=true, and start Docker with UNLEASH_DOCKER_IMAGE=unleashorg/unleash-enterprise:latest. You also need a valid license key provided as UNLEASH_DEV_LICENSE=<your license key>.
A basic test is automatically generated by the tool (find them under client/test), but they don't have a default configuration and doesn't have payloads required for some of the endpoints. This is the reason why the tools marks all of them as Skip. Still they're a good starting point.
We recommend copying specific tests from client/test into test and adapting them accordingly. We've done that already for api_users_test and some of its methods. Also, recommended to use apiClient := testClient() to instantiate the client.
- (optional but recommended)
docker compose rm --force docker compose upgo test ./test/... -count=1 -vUNLEASH_ENTERPRISE=true go test ./test/... -count=1 -v
PRs from forks do not get access to repository secrets in GitHub Actions (for example UNLEASH_DEV_LICENSE), so enterprise matrix jobs may fail in the fork context.
To validate the same changes with secrets enabled:
- Fetch the PR head into a local branch:
git fetch origin pull/<PR_NUMBER>/head:pr-<PR_NUMBER>- Push that branch to this repository:
git push origin pr-<PR_NUMBER>-
Run the workflow on
pr-<PR_NUMBER>from the base repository Actions page. -
(optional) Delete the temporary branch when done:
git push origin --delete pr-<PR_NUMBER>