Zero-setup SDK generator wrapping OpenAPI Generator
Project description
swain_cli
swain_cli is a zero-setup CLI that wraps OpenAPI Generator so you can generate SDKs without installing Java or the generator yourself. The package vendors the OpenAPI Generator JAR, fetches a trimmed Temurin JRE on demand, and keeps everything cached per-user for reproducible results.
Why swain_cli
- Generate SDKs for multiple target languages with one command
- Pinned OpenAPI Generator
7.6.0for consistent output across machines - Embedded OpenJDK 21 runtime download on first use (or opt into system Java)
- Light Python dependency stack (Typer, httpx, questionary, platformdirs, keyring, pooch) that stays friendly for
pipx, CI, and ephemeral environments - Helper commands to inspect and manage the embedded engine assets
Install
pipx install swain_cli
Python 3.8 or newer is required. Installing via
pipxkeeps swain_cli isolated from other tooling. You can also usepip install swain_cliinside a virtual environment if you prefer.
First run
# (optional) Pre-install the embedded runtime to skip the first-run download
swain_cli engine install-jre
# (optional) Guided wizard that builds your swain_cli gen command
swain_cli interactive
# List all bundled generators (delegates to the pinned OpenAPI Generator)
swain_cli list-generators
# Generate Python and TypeScript clients into ./sdks/<generator>
swain_cli gen -i ./openapi.yaml -l python -l typescript -o ./sdks \
-p packageName=my_api_client -p packageVersion=0.2.2
swain_cli streams OpenAPI Generator output directly, so you see progress as the SDK is generated.
Command overview
swain_cli gen— generate one or more SDKs; accepts the same configuration flags as OpenAPI Generator (-c,-t,-p, etc.) and repeatable-l/--langoptions. By default swain_cli pulls the CrudSQL dynamic swagger fromhttps://api.swain.technology; override with--crudsql-urlor provide-i/--schemato use a local file/URL instead.- Add
--swain-project-idand--swain-connection-idto resolve the schema from a specific Swain project/connection after authenticating. When these flags are present swain_cli fetches the connection's current build, resolves the deployed endpoint, and downloads/api/dynamic_swaggerautomatically.
- Add
swain_cli interactive— answer a short Q&A and swain_cli assembles (and optionally runs) the matchingswain_cli gencommandswain_cli list-generators— enumerate supported generators; add--engine systemto check a local Java installationswain_cli doctor— print environment details, cache paths, installed JREs, and whether the vendor JAR is availableswain_cli auth— log in, log out, or inspect authentication state for future swain_cli featuresswain_cli engine <action>— manage the embedded runtime (status,install-jre,update-jar,use-system,use-embedded)
Run swain_cli --help or swain_cli <command> --help for complete usage.
Authentication
Use the auth subcommands to prime swain_cli with credentials for the hosted platform you will be integrating with.
swain_cli auth login: Supply an access token via--token <value>, pipe it with--stdin, or let swain_cli prompt securely. The token is stored in the system keyring (or useSWAIN_CLI_AUTH_TOKENfor ephemeral sessions).swain_cli auth status: Inspect the currently active token source and see where swain_cli will read credentials from.swain_cli auth logout: Delete the stored token if you need to rotate or clear credentials.- Tokens live in the system keyring; use
SWAIN_CLI_AUTH_TOKENfor ephemeral sessions or automation. - The
swain_cli interactivewizard begins by checking for an access token and will prompt you to add or replace one before continuing if none is available. - Credential login: run
swain_cli auth login --credentials --username you@example.comto let the CLI callPOST /auth/login, prompt for your password securely, and store both the access and refresh token in the keyring. Supplying--password <value>works for non-interactive use, but piping via stdin or prompting is safer so the secret does not end up in shell history.
+--------------------+
| swain_cli auth login |
+----------+---------+
|
+--------------------------+---------------------------+
| | |
--token flag --stdin (piped input) interactive prompt
| | |
+--------------------------+---------------------------+
|
v
+------------------------------+
| store credential in keyring |
+----------+-------------------+
|
resolve_auth_token()
|
+--------------+--------------+
| |
SWAIN_CLI_AUTH_TOKEN set? keyring credential?
| |
use env token use masked value from keyring
| |
+--------------+--------------+
|
v
+--------------------+
| authenticated CLI |
| requests (future) |
+--------------------+
SWAIN_CLI_AUTH_TOKEN always takes precedence over anything written to disk, which is useful for one-off runs in CI. Pair swain_cli auth status with SWAIN_CLI_CONFIG_DIR to verify exactly which file swain_cli will read when the CLI gains authenticated commands.
CrudSQL integration
swain_cli gen(with no schema flag) automatically downloads the CrudSQL schema document fromhttps://api.swain.technologyusing the stored token as aBearercredential before running OpenAPI Generator. The CLI first calls/api/schema-locationto resolve the live schema URL, then falls back to the legacy/api/dynamic_swaggerpath if discovery fails. (The production endpoint is still being finalized; expect this URL to change.)- Override the source with
--crudsql-url https://api.example.comor bypass CrudSQL entirely by supplying-i/--schema. - The retrieved schema is cached to a temp file for the duration of the command and removed afterwards.
+-----------------------------------+
| swain_cli gen / interactive wizard |
+----------------+------------------+
|
schema flag provided?
(-i / --schema)
yes / \ no
v v
use provided path/URL CrudSQL base selected?
|
+-----------------+-----------------+
| |
flag or wizard override? default host (Swain)
(--crudsql-url) https://api.swain.technology
| |
v v
resolve schema location -> download document with stored token
|
v
run OpenAPI Generator for each language
Generating clients effectively
- Multiple targets: Pass
-l/--langrepeatedly (swain_cli gen ... -l python -l typescript) and each generator gets its own subfolder beneath the output directory. - Custom generator config: Provide OpenAPI Generator configuration with
-c ./configs/python.yamland template overrides via-t ./templates/python. - Additional properties: Use
-p key=value(repeatable) or--generator-arg "--enable-post-process-file"to forward advanced options. - TypeScript alias:
typescriptautomatically maps totypescript-axios; requesttypescript-fetchexplicitly if you need the alternative runtime.
Engine modes and caching
- Embedded engine (default): On first use, swain_cli downloads a platform-specific JRE archive from the project’s GitHub Releases and stores it with the vendor JAR under the user cache directory (see below).
- System engine: Add
--engine system(or exportSWAIN_CLI_ENGINE=system) to use whateverjavais onPATH. This is handy on servers where the embedded download is blocked or not desired. - Cache location: By default caches live under
~/.cache/swain_cli(Linux),~/Library/Caches/swain_cli(macOS), or%LOCALAPPDATA%\swain_cli\cache(Windows). Override the root withSWAIN_CLI_CACHE_DIR=/custom/path. - Offline use: Prime the cache by running
swain_cli engine install-jrebefore going offline, or copy an existing cache directory to new machines.
Running in CI
- Install the CLI (for example
pipx install swain_cliorpip install swain_cli). - Pre-install the embedded engine at build time (
swain_cli engine install-jre) to avoid downloading during critical steps. - Cache the swain_cli cache directory between jobs to reuse the JRE and downloaded JARs.
- Invoke
swain_cli genwith your schema and desired generators; capture the generated SDK directories as build artifacts.
Troubleshooting
- Download failures: Check your proxy/firewall. You can download the JRE artifact manually from the GitHub release and place it under the cache path shown by
swain_cli doctor. - Missing generators:
swain_cli list-generators --engine systemverifies what your system Java installation provides. If you updated OpenAPI Generator viaswain_cli engine update-jar, rerunlist-generatorsto ensure the new jar is active. - Cache cleanup: Delete the cache directory printed by
swain_cli doctorto force a clean fetch of the runtime and JAR.
Contributing
- Create a virtual environment (
python -m venv .venv) and activate it. - Install the project in editable mode with dev extras:
pip install -e .[dev]. - Run the CLI locally via
python -m swain_cli.cli --helpor theswain_cliconsole script. - Update or add tests and run them with
python -m pytest.
Maintainers
- Use the
build-jreGitHub Action (workflow dispatch) to produce trimmed JRE archives for Linux (x86_64 + arm64), macOS (Intel + Apple Silicon), and Windows. Optionally provide arelease_tagto upload artifacts directly to ajre-<version>release. - After the workflow finishes, copy the resulting
.sha256values intoswain_cli/cli.pyso the CLI can verify downloads, and adjustASSET_BASEif you publish assets under a new release tag. - Trigger the
releaseworkflow by pushing av*tag once assets are in place. It builds the PyPI distributions and optional PyInstaller binaries. The full release runbook lives indocs/RELEASING.md.
Third-party notices
- OpenAPI Generator (Apache 2.0)
- Eclipse Temurin OpenJDK (GPLv2 with Classpath Exception)
License
swain_cli is released under the Apache 2.0 license. See LICENSE for details.
- Swain backend discovery: With an auth token configured, you can run
swain_cli interactiveto browse your Swain projects and connections. The wizard lists projects, lets you pick a connection, and then downloads the matching dynamic swagger behind the scenes. To script the same behaviour non-interactively, pass--swain-project-id <id>and--swain-connection-id <id>toswain_cli gen.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swain_cli-0.2.2.tar.gz.
File metadata
- Download URL: swain_cli-0.2.2.tar.gz
- Upload date:
- Size: 26.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aa2de43b02c5fe2e1e9cd003cd86bf09005824610daec17e4918e008ffc7eec
|
|
| MD5 |
5737363b9458ec7def748b83a5533582
|
|
| BLAKE2b-256 |
29212bd281a02cc89e81a02c10d55e5112442be370b3459ad5f2516a66152a5b
|
File details
Details for the file swain_cli-0.2.2-py3-none-any.whl.
File metadata
- Download URL: swain_cli-0.2.2-py3-none-any.whl
- Upload date:
- Size: 26.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab886ea8bff7ed84ac27fa79d8289526b747feadfbd886a59fd5853d6bc6e74d
|
|
| MD5 |
2ce0c5200090459b08d3d310c79559e9
|
|
| BLAKE2b-256 |
651f7bb4fe5463faec07e9db636300ffba7f7599edf1dbd8a7d2186dcb6b43af
|