Skip to main content

Zero-setup SDK generator wrapping OpenAPI Generator

Project description

swain_cli

swain_cli is a zero-setup CLI around OpenAPI Generator. It vendors the generator JAR, downloads a trimmed Temurin JRE on demand, and caches everything per user so you can build SDKs consistently without installing Java yourself.

Highlights

  • Generate SDKs for multiple languages with a single command or an interactive wizard
  • Ship exactly what you test with OpenAPI Generator 7.6.0 pinned inside the toolchain
  • Launch the bundled OpenJDK 21 runtime automatically (or opt into your own java)
  • Keep dependencies light (Typer, httpx, questionary, platformdirs, keyring, pooch) so pipx, CI, and ephemeral environments stay happy
  • Inspect and manage the embedded engine with helper commands (engine, doctor, list-generators)

Installation

Binary (no Python required)

  • macOS/Linux:
    curl -fsSL https://raw.githubusercontent.com/takifouhal/swain_cli/HEAD/scripts/install.sh | bash
    
  • Windows (PowerShell):
    iwr -useb https://raw.githubusercontent.com/takifouhal/swain_cli/HEAD/scripts/install.ps1 | iex
    

The single-file binary bundles a Python runtime, so no system Python is needed. On first run, swain_cli downloads a trimmed Temurin JRE for your platform and caches it.

Notes:

  • Linux arm64 is supported (built via emulated runner).
  • Windows on ARM uses the x86_64 binary and runs under emulation.

pip/pipx (requires Python 3.8+)

pipx install swain_cli

Installing with pipx keeps swain_cli isolated; alternatively run pip install swain_cli in a virtual environment.

Quick start

# Prime the embedded runtime so the first real run is instant
swain_cli engine install-jre

# Explore generators and craft a command via guided prompts
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.3.0

swain_cli streams generator output directly so you see progress in real time.

Generating SDKs

  • swain_cli gen accepts every OpenAPI Generator flag you already know (-c, -t, -p, etc.) and repeatable -l/--lang options.
  • By default the CLI downloads the CrudSQL dynamic swagger from https://api.swain.technology. Override with --crudsql-url, point to a local spec via -i/--schema, or combine both for multi-source workflows.
  • Swain project integration: provide --swain-project-id and --swain-connection-id to resolve the deployed connection swagger automatically after authenticating. The CLI will find the active build, fetch /api/dynamic_swagger, and feed it to the generator.
  • JVM tuning: runs start with -Xms2g -Xmx10g -XX:+UseG1GC. If the build still runs out of memory the CLI retries at -Xmx14g. Supply extra options with --java-opt (repeatable) or export SWAIN_CLI_JAVA_OPTS.
  • Docs/tests are disabled by default via --global-property=apiDocs=false,apiTests=false,modelDocs=false,modelTests=false; override with your own --generator-arg when you need them.
  • To match modern OAS defaults the CLI automatically adds -p disallowAdditionalPropertiesIfNotPresent=false. Opt into stricter behaviour with -p disallowAdditionalPropertiesIfNotPresent=true or a generator config file.
  • The typescript shortcut maps to typescript-axios; request typescript-fetch explicitly when you need that runtime.

Command reference

  • swain_cli interactive — ask a short set of questions, preview the matching swain_cli gen command, and optionally run it on the spot. Seed the wizard with --java-opt and pass raw OpenAPI Generator flags via --generator-arg so interactive runs match your scripts.
  • swain_cli list-generators — enumerate all generators shipped in the embedded JAR. Add --engine system to validate a local Java installation instead.
  • swain_cli doctor — print environment information, cache paths, installed JREs, and JAR availability to help diagnose setup issues.
  • swain_cli auth — manage credentials for hosted Swain services (login, logout, status). Tokens live in the system keyring; use SWAIN_CLI_AUTH_TOKEN for ephemeral automation.
  • swain_cli engine <action> — switch between the embedded runtime and your system Java, install the JRE ahead of time, or update the pinned JAR.

Run swain_cli --help or swain_cli <command> --help for full usage.

Authentication

Use the auth subcommands to prepare credentials before generating SDKs against hosted Swain projects.

  • swain_cli auth login — provide an access token via --token <value>, pipe it with --stdin, or let the CLI prompt securely. Tokens are stored in the system keyring unless you set SWAIN_CLI_AUTH_TOKEN.
  • swain_cli auth login --credentials --username you@example.com — authenticate via username/password (POST /auth/login). Access and refresh tokens are stored automatically.
  • swain_cli auth status — inspect the active token source and storage location.
  • swain_cli auth logout — clear the stored token.
  • The interactive wizard checks for a token before listing projects and will prompt you to add or replace one if missing.

Engine modes and caching

  • Embedded engine (default) — the first run downloads a platform-specific Temurin JRE and caches it alongside the vendor JAR under ~/.cache/swain_cli (Linux), ~/Library/Caches/swain_cli (macOS), or %LOCALAPPDATA%\swain_cli\cache (Windows). Override with SWAIN_CLI_CACHE_DIR.
  • System engine — add --engine system (or export SWAIN_CLI_ENGINE=system) to run with whatever java is already on PATH.
  • Offline use — prime the cache via swain_cli engine install-jre or copy an existing cache directory between machines.

Running in CI

  1. Install the package (pipx install swain_cli or pip install swain_cli).
  2. Pre-install the embedded runtime during setup: swain_cli engine install-jre.
  3. Cache the swain_cli cache directory between jobs to reuse downloads.
  4. Invoke swain_cli gen with your schema and desired generators; capture ./sdks (or your chosen output path) as build artefacts.

Troubleshooting

  • Download failures — check proxy/firewall configuration, or download the JRE asset manually from the GitHub release and place it under the cache path from swain_cli doctor.
  • Missing generators — run swain_cli list-generators --engine system to validate your local Java installation or after updating the JAR with engine update-jar.
  • Cache cleanup — delete the directory printed by swain_cli doctor to force a clean fetch of the runtime and JAR.
  • OutOfMemoryError — the CLI already retries with a larger heap. For massive specs raise the ceiling with repeatable --java-opt -Xmx16g or set SWAIN_CLI_JAVA_OPTS.

Contributing

  1. Create a virtual environment (python -m venv .venv) and activate it.
  2. Install the project with dev extras: pip install -e .[dev].
  3. Run the CLI locally via python -m swain_cli.cli --help or the swain_cli entry point.
  4. Add or update tests and run python -m pytest.

Maintainers

  • Trigger the build-jre workflow (workflow dispatch) to build trimmed JRE archives for Linux (x86_64 + arm64), macOS (Intel + Apple Silicon), and Windows. Provide an optional release_tag to publish directly to a jre-<version> release.
  • Copy the resulting .sha256 values into swain_cli/cli.py so downloads can be verified, and update ASSET_BASE if you move assets to a new release tag.
  • Tag releases (git tag vX.Y.Z) once assets are ready. The full release runbook lives in docs/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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swain_cli-0.3.3.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swain_cli-0.3.3-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file swain_cli-0.3.3.tar.gz.

File metadata

  • Download URL: swain_cli-0.3.3.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for swain_cli-0.3.3.tar.gz
Algorithm Hash digest
SHA256 936223604d1519cab25857dc27f4aa73faf47dcafd9a6661071df7e899998671
MD5 dd032f35a786b20e2ce4e5109277c634
BLAKE2b-256 db141a3935c03698d41d2f5e803f658a3b3679f3fdba61e6629cb539e8fc7724

See more details on using hashes here.

File details

Details for the file swain_cli-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: swain_cli-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for swain_cli-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9d2709ef6130c4fa31998aa43b3c4237ff4c195cd1a66c2547087accda23d3d2
MD5 2d9dff6deed5ea571856e78cce34ea9d
BLAKE2b-256 9427698dd8e4e0f54a07ade5ad69c918a25b3b0d0db0434d8ce146a6af670a8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page